Not a Member Yet,
Click here to Register
How do you like the new design?
It's cool, great job
[tally: 70%] 70%
It's okay
[tally: 20%] 20%
Its OK but I liked the old layout better
[tally: 0%] 0%
Please bring the old one back
[tally: 10%] 10%

votes: 10

ID: 413
Viewed: 2721
Added: Aug 19, 2002
Version:
Snippet uploaded by: snippet
Written By: Dean Cleaver
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

How to find out if a Service Is Running

Highlight all by clicking in box
<!---Declaration--->
' 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


Highlight All
<!---Code--->
'
' Here's where we test if the service is running
'

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
;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 snippetlibrary.com All Rights Reserved. Conditions