|
|
|
Click here to copy the following block | Private 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
Private Declare Function OpenSCManager Lib "advapi32.dll" Alias _ "OpenSCManagerA" (ByVal lpMachineName As String, _ ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long Private Declare Function CloseServiceHandle Lib "advapi32.dll" (ByVal hSCObject _ As Long) As Long Private Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA" _ (ByVal hSCManager As Long, ByVal lpServiceName As String, _ ByVal dwDesiredAccess As Long) As Long Private Declare Function StartService Lib "advapi32.dll" Alias "StartServiceA" _ (ByVal hService As Long, ByVal dwNumServiceArgs As Long, _ ByVal lpServiceArgVectors As Long) As Long Private Declare Function ControlService Lib "advapi32.dll" (ByVal hService As _ Long, ByVal dwControl As Long, lpServiceStatus As SERVICE_STATUS) As Long
Const GENERIC_EXECUTE = &H20000000 Const SERVICE_CONTROL_STOP = 1 Const SERVICE_CONTROL_PAUSE = 2 Const SERVICE_CONTROL_CONTINUE = 3
Function ServiceCommand(ByVal ServiceName As String, ByVal command As Long) As _ Boolean Dim hSCM As Long Dim hService As Long Dim res As Long Dim lpServiceStatus As SERVICE_STATUS If command < 0 Or command > 3 Then Err.Raise 5 hSCM = OpenSCManager(vbNullString, vbNullString, GENERIC_EXECUTE) If hSCM = 0 Then Exit Function hService = OpenService(hSCM, ServiceName, GENERIC_EXECUTE) If hService = 0 Then GoTo CleanUp Select Case command Case 0 res = StartService(hService, 0, 0) Case SERVICE_CONTROL_STOP, SERVICE_CONTROL_PAUSE, _ SERVICE_CONTROL_CONTINUE res = ControlService(hService, command, lpServiceStatus) End Select If res = 0 Then GoTo CleanUp ServiceCommand = True
CleanUp: If hService Then CloseServiceHandle hService CloseServiceHandle hSCM End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|