dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: windows service application

  1. #11
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    Yeah, before running a service, it must be installed on the computer, Configuration Pannel -> Service, and you need administrator right to install / uninstall it, you can look the service already installed on your computer with regedit:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

    You might also want your service to use an NT account and his password, because your service will be running even if no one is logged, so if you use ADO (for example), you absolutely need registry key, and when no user is connected, no registry, error and, because a service, you don't know when it is bugged (except if you use custom log or the NTService logevent that write to NT log)

    JeffB

  2. #12
    Join Date
    Aug 2002
    Posts
    63

    Thumbs up

    Originally posted by DSJ
    The first time you run it you must pass -install as a commandline parameter to install it as a service. Your command line should look like

    YouServiceName.exe -install
    hi dsj,

    my serive exe is called "sample.exe"
    so i have to give 'sample.exe -install' in the command prompt isn't ?
    or do i have to give the path where it recides.
    I dont get exactly what you are saying,when i type that in my command prompt it gives an error saying "command not recognised"
    could you be a little more specific.
    Or is there anything else i have to do.

    thanks

  3. #13
    Join Date
    Aug 2002
    Posts
    63
    Originally posted by JeffB
    Yeah, before running a service, it must be installed on the computer, Configuration Pannel -> Service, and you need administrator right to install / uninstall it, you can look the service already installed on your computer with regedit:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

    You might also want your service to use an NT account and his password, because your service will be running even if no one is logged, so if you use ADO (for example), you absolutely need registry key, and when no user is connected, no registry, error and, because a service, you don't know when it is bugged (except if you use custom log or the NTService logevent that write to NT log)

    JeffB
    hi jeff,

    hi dsj,

    my serive exe is called "sample.exe"
    so i have to give 'sample.exe -install' in the command prompt isn't ?
    or do i have to give the path where it recides.
    I dont get exactly how and what you are saying,when i type that in my command prompt it gives an error saying "command not recognised"
    could you be a little more specific.
    Or is there anything else i have to do.


    thanks

  4. #14
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    There's three way to do it:

    >First, compile your EXE with Visual Basic (create the EXE, not execute the program), after, go to MSDOS, browse your HardDisk by using cd.. and cd /NameFolder (or type C: to go to the root of your C Next, when it come to your EXE, type sample -install, it will look like C:\AppName\> sample -install

    >Second, go to StartMenu, go to Execute, on the little window, go to browse, select your EXE (sample.exe), add to the text that should be sample.exe " -install" so it will be writed in the textbox: "sample.exe -install"

    >Directly from VB, when you compile your code and execute it FROM VB, you can add command property, before running the app, go to -project/property of sample, then on the tab create, search for the textbox parameters of the command line (my version is in french, so the translate might be innaccurate ), then type -install

    >Because Service are a little special, your project will need a documentation, for any one that must install it on his computer, they must know to type -install, to have administrator rights and to type -uninstall (or whatever you want the parameters to be, I was using -i and -u)

    JeffB - hope it helps

  5. #15
    Join Date
    Aug 2002
    Posts
    63

    Thumbs up

    Originally posted by JeffB
    There's three way to do it:

    >First, compile your EXE with Visual Basic (create the EXE, not execute the program), after, go to MSDOS, browse your HardDisk by using cd.. and cd /NameFolder (or type C: to go to the root of your C Next, when it come to your EXE, type sample -install, it will look like C:\AppName\> sample -install

    >Second, go to StartMenu, go to Execute, on the little window, go to browse, select your EXE (sample.exe), add to the text that should be sample.exe " -install" so it will be writed in the textbox: "sample.exe -install"

    >Directly from VB, when you compile your code and execute it FROM VB, you can add command property, before running the app, go to -project/property of sample, then on the tab create, search for the textbox parameters of the command line (my version is in french, so the translate might be innaccurate ), then type -install

    >Because Service are a little special, your project will need a documentation, for any one that must install it on his computer, they must know to type -install, to have administrator rights and to type -uninstall (or whatever you want the parameters to be, I was using -i and -u)

    JeffB - hope it helps

    Hey Jeff,

    That was of great help.thanks a lot.Actually i have to query a database and perform certain actions...do you think i can do this ?
    I will give it a try on monday.
    Also if you have any idea about VB.NET:-My question is If i create a EXE in VB.NET and have to install in client systems,what are the minimum requirements for that client machine.

    Thanks.
    Have a great week end.

  6. #16
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    Hi, if you use ADO or OLEDB, you will need to have your service run with an NT account, you can set the account and password with the OCX, or by the configuration pannel -> services, select your service, and instead of using system account, use user account with the full form: if your user account is balajigr1214, use the form SERDIV/balajigr1214

    For VB.Net, I don't know really about, there is a vb.net forum here, and I think that this is not much requirement, it is more the developper computer that will need to be better than the one that run the compiled exe.

    JeffB - have a nice day (night...)

  7. #17
    Join Date
    May 2001
    Posts
    7
    .NET Framewrork will be needed on the client PCs. It better to have the service run on the server and the client query that server for data ...

  8. #18
    Join Date
    May 2001
    Posts
    7
    Reading this thread in its totality I think Jeff has some good knowledge about exe. I want to know if there is a way to dettect that a exe is not running and if it is not running then to activate it ... Activating is not a problem actually .. The only thing is how to detect that a exe is activated ...

    thanks.

  9. #19
    Join Date
    Aug 2002
    Posts
    63

    Smile

    [QUOTE]Originally posted by JeffB
    Hi, if you use ADO or OLEDB, you will need to have your service run with an NT account, you can set the account and password with the OCX, or by the configuration pannel -> services, select your service, and instead of using system account, use user account with the full form: if your user account is balajigr1214, use the form SERDIV/balajigr1214

    For VB.Net, I don't know really about, there is a vb.net forum here, and I think that this is not much requirement, it is more the developper computer that will need to be better than the one that run the compiled exe.

    JeffB - have a nice day (night...)
    [/QUO
    TE]

    Hi Jeff,

    Thanks,i will be working on the services very soon.All this as helped me a lot.Maybe if any doubt i will get back to you.

    Bye

  10. #20
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    That code will allow you to detect, for example, if the process notepad.exe is running. It will only do a msgbox if it find the process. Remember, their can be a lot of process that have the same name, but different PIDS. Try the program while their is many notepad opened, you'll see. You should rearranged all of the code to make a function where you pass a EXE name and that return an array of PIDS number. Oh well, here it is :

    Code:
    Option Explicit
       
    Private Declare Function EnumProcesses Lib "psapi.dll" _
                            (lpidProcess As Long, _
                             ByVal cb As Long, _
                             cbNeeded As Long) As Long
    
    Private Declare Function OpenProcess Lib "kernel32" _
                            (ByVal dwDesiredAccess As Long, _
                             ByVal bInheritHandle As Long, _
                             ByVal dwProcessId As Long) As Long
    
    Private Declare Function EnumProcessModules Lib "psapi.dll" _
                            (ByVal hProcess As Long, _
                             lphModule As Long, _
                             ByVal cb As Long, _
                             lpcbNeeded As Long) As Long
    
    Private Declare Function GetModuleBaseName Lib "psapi.dll" _
    Alias "GetModuleBaseNameA" _
                            (ByVal hProcess As Long, _
                             ByVal hModule As Long, _
                             ByVal lpBaseName As String, _
                             ByVal nSize As Long) As Long
    
    Private Declare Function CloseHandle Lib "kernel32" _
                            (ByVal hObject As Long) As Long
                            
                            
    Private Sub Command1_Click()
    
        
        Dim lngPIDList() As Long                           '  The list of the Process (PIDs)
        Dim lngNumberOfPID As Long                     '  Number of PIDs
        
        Dim lngReturnValue As Long                       '  Return value of Win32 function
        Dim lngNumberOfBytesReceived As Long       '  Number of Bytes received from EnumProcess()
                       
        Dim lngProcessHandle As Long                    '  Process Handle (OpenProcess)
        Dim lngModuleHandle As Long                     '  Module Handle  (EnumProcessModule)
        Dim strProcessName As String                    '  Name of the process
        
        Dim strExe As String
        strExe = "notepad.exe"                              ' Name of the researched process
            
        Dim i As Long                                           ' For...Next i
        Dim lngNumberOfProcessFound As Long         'How many notepad.exe have we found?
        lngNumberOfProcessFound = 0
        
        lngNumberOfPID = 100
        
        ReDim lngPIDList(lngNumberOfPID)
        
        'Return the list of process (PIDS number)
        lngReturnValue = EnumProcesses(lngPIDList(0), lngNumberOfPID * 4, lngNumberOfBytesReceived)
        If lngReturnValue = 0 Then
            MsgBox "RED-ALERT: No PID returned (EnumProcess)"
            Exit Sub
        End If
            
        'How many process do we receive???
        lngNumberOfPID = lngNumberOfBytesReceived / 4
        
        If lngNumberOfPID = 0 Then
            MsgBox "No process corresponding to :" & strExe
        End If
       
        For i = 0 To lngNumberOfPID - 1
        
            ' Process 0, 2, and 28 are special process we don't want to analyse them
            If lngPIDList(i) = 0 Or lngPIDList(i) = 2 Or lngPIDList(i) = 28 Then GoTo NextProcess
            
            '  Retrieve an handle on the process
            lngProcessHandle = OpenProcess(&H400 Or &H10, 0&, lngPIDList(i))
            If lngProcessHandle = 0 Then GoTo NextProcess
              
            'Retrieve an handle on the fist module of the process (first module is always
            'the EXE)
            lngModuleHandle = 0
            lngReturnValue = EnumProcessModules(lngProcessHandle, lngModuleHandle, 4&, lngNumberOfBytesReceived)
            If lngReturnValue = 0 Then GoTo NextProcess
                    
            ' Get the name of the module
            strProcessName = String$(256, 0)
            lngReturnValue = GetModuleBaseName(lngProcessHandle, lngModuleHandle, strProcessName, Len(strProcessName))
            If lngReturnValue = 0 Then GoTo NextProcess
            strProcessName = Replace(strProcessName, Chr(0), "")
    
            ' Is that the name we are searching?
            If UCase$(strProcessName) = UCase$(strExe) Then
                lngNumberOfProcessFound = lngNumberOfProcessFound + 1
                MsgBox strProcessName & " " & lngPIDList(i), vbOKOnly, "Result"
            End If
                         
    NextProcess:
            
            ' Close the handle of the process
            If lngProcessHandle > 0 Then CloseHandle (lngProcessHandle)
            
            Next i
            
        If lngNumberOfProcessFound = 0 Then
            MsgBox "No process ---" & strExe & "--- founded.", vbOKOnly, "Result"
        End If
        
        
    End Sub
    sorry for misaligned text ...

    JeffB
    Last edited by JeffB; October 24th, 2004 at 08:48 PM.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)