How to find out if a service is started? 
Author Message
 How to find out if a service is started?

How do I find out if a service has started yet (just after starting
Windows)?



Sat, 21 Oct 2000 03:00:00 GMT  
 How to find out if a service is started?

Try this code - it's been cut from my app so if I missed something sorry :-)

' Service database names
Public Const SERVICES_ACTIVE_DATABASE = "ServicesActive"

' Service Control Manager object specific access types
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const SC_MANAGER_CONNECT = &H1
Public Const SC_MANAGER_CREATE_SERVICE = &H2
Public Const SC_MANAGER_ENUMERATE_SERVICE = &H4
Public Const SC_MANAGER_LOCK = &H8
Public Const SC_MANAGER_QUERY_LOCK_STATUS = &H10
Public Const SC_MANAGER_MODIFY_BOOT_CONFIG = &H20

Public Const SC_MANAGER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or
SC_MANAGER_CONNECT Or SC_MANAGER_CREATE_SERVICE Or
SC_MANAGER_ENUMERATE_SERVICE Or SC_MANAGER_LOCK Or
SC_MANAGER_QUERY_LOCK_STATUS Or SC_MANAGER_MODIFY_BOOT_CONFIG)

'Service object specific access types
Public Const SERVICE_QUERY_CONFIG = &H1
Public Const SERVICE_CHANGE_CONFIG = &H2
Public Const SERVICE_QUERY_STATUS = &H4
Public Const SERVICE_ENUMERATE_DEPENDENTS = &H8
Public Const SERVICE_START = &H10
Public Const SERVICE_STOP = &H20
Public Const SERVICE_PAUSE_CONTINUE = &H40
Public Const SERVICE_INTERROGATE = &H80
Public Const SERVICE_USER_DEFINED_CONTROL = &H100

Public Const SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or
SERVICE_QUERY_CONFIG Or SERVICE_CHANGE_CONFIG Or SERVICE_QUERY_STATUS Or
SERVICE_ENUMERATE_DEPENDENTS Or SERVICE_START Or SERVICE_STOP Or
SERVICE_PAUSE_CONTINUE Or SERVICE_INTERROGATE Or
SERVICE_USER_DEFINED_CONTROL)

' Service State -- for CurrentState
Public Const SERVICE_STOPPED = &H1
Public Const SERVICE_START_PENDING = &H2
Public Const SERVICE_STOP_PENDING = &H3
Public Const SERVICE_RUNNING = &H4
Public Const SERVICE_CONTINUE_PENDING = &H5
Public Const SERVICE_PAUSE_PENDING = &H6
Public Const SERVICE_PAUSED = &H7

Public Type SERVICE_STATUS
        dwServiceType As Long
        dwCurrentState As Long
        dwControlsAccepted As Long
        dwWin32ExitCode As Long
        dwServiceSpecificExitCode As Long
        dwCheckPoint As Long
        dwWaitHint As Long
End Type

Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA"
(ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal
dwDesiredAccess As Long) As Long
Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA" (ByVal
hSCManager As Long, ByVal lpServiceName As String, ByVal dwDesiredAccess As
Long) As Long
Declare Function QueryServiceStatus Lib "advapi32.dll" (ByVal hService As
Long, lpServiceStatus As SERVICE_STATUS) As Long

    Dim lhSCManager As Long
    Dim lhService As Long
    Dim lhServiceStatus As Long

    lhSCManager = OpenSCManager("Computer Name", SERVICES_ACTIVE_DATABASE,
SC_MANAGER_ALL_ACCESS)
    If lhSCManager <> 0 Then
        lhService = OpenService(lhSCManager, "Service Name",
SERVICE_ALL_ACCESS)
        If lhService <> 0 Then
            lhServiceStatus = QueryServiceStatus(lhService, ServiceStatus)
            If lhServiceStatus <> 0 Then
                Select Case ServiceStatus.dwCurrentState
                    Case SERVICE_STOPPED
                    Case SERVICE_START_PENDING
                    Case SERVICE_STOP_PENDING
                    Case SERVICE_RUNNING
                    Case SERVICE_CONTINUE_PENDING
                    Case SERVICE_PAUSE_PENDING
                    Case SERVICE_PAUSED
                End Select
                CloseServiceHandle lhServiceStatus
            End If
            CloseServiceHandle lhService
        End If
        CloseServiceHandle lhSCManager
    End If

HTH
Cheers,
Dino


Quote:
>How do I find out if a service has started yet (just after starting
>Windows)?



Sun, 22 Oct 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Start 4 Services Check that they have succesfuly started

2. Where can i find Com+ Services type library or Component services com+ 1.0 for Win98

3. Windows Find (Start:Find:Files and Folders)

4. I am starting out and need some help

5. I am starting to prefer comboboxes than textboxes

6. Am beginning, can someone help me start, PLEASE!

7. university EMR send outs

8. on the outs

9. Learning the ins and outs of Peek and Poke

10. How to handle print outs in VB?

11. Filesystem Time outs

12. Session Variable Time-outs

 

 
Powered by phpBB® Forum Software