Private Const MAX_PATH = 260
Private Const SC_MANAGER_CREATE_SERVICE = &H2
Private Const SERVICE_START = &H10
Private Const DELETE = &H10000
Private Const SERVICE_KERNEL_DRIVER = &H1
Private Const SERVICE_DEMAND_START = &H3
Private Const SERVICE_ERROR_IGNORE = 0&
Private Const SERVICE_STOP = &H20
Private Declare Function OpenSCManager
Lib "advapi32.dll"
Alias "OpenSCManagerA" (
ByVal lpMachineName
As Long,
ByVal lpDatabaseName
As Long,
ByVal dwDesiredAccess
As Long)
As Long
Private Declare Function GetFullPathName
Lib "kernel32"
Alias "GetFullPathNameA" (
ByVal lpFileName
As String,
ByVal nBufferLength
As Long,
ByVal lpBuffer
As String, lpFilePart
As Long)
As Long
Private Declare Function CreateService
Lib "advapi32.dll"
Alias "CreateServiceA" (
ByVal hSCManager
As Long,
ByVal lpServiceName
As String,
ByVal lpDisplayName
As String,
ByVal dwDesiredAccess
As Long,
ByVal dwServiceType
As Long,
ByVal dwStartType
As Long,
ByVal dwErrorControl
As Long,
ByVal lpBinaryPathName
As String,
ByVal lpLoadOrderGroup
As Long, lpdwTagId
As Long,
ByVal lpDependencies
As Long,
ByVal lp
As Long,
ByVal lpPassword
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 DeleteService
Lib "advapi32.dll" (
ByVal hService
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
Dim hSCManager
As Long
Dim hService
As Long
Dim drName
As String, drDisplayName
As String, drPath
As String
Private Sub Command2_Click()
drName = cd.FileTitle
drDisplayName = drName
hSCManager = OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE)
hService = OpenService(hSCManager, drName, SERVICE_START
Or DELETE
Or SERVICE_STOP)
If hService
Then
'ret = CloseServiceHandle(hService)
ret = DeleteService(hService)
ret = CloseServiceHandle(hService)
End If
hSCManager = OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE)
hService = CreateService(hSCManager, drName, drDisplayName, _
SERVICE_START + DELETE, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, _
SERVICE_ERROR_IGNORE, drPath,
ByVal 0&,
ByVal 0&,
ByVal 0&,
ByVal 0&,
ByVal 0&
ret = StartService(hService, 0, 0)
ret = DeleteService(hService)
ret = CloseServiceHandle(hService)
End Sub