为了回答这个问题,我已经给一些网友发了必要的ACTIVEX,这里给大家一个例子:
Sub Main()
Load Form1
Dim strDisplayName As String
On Error GoTo Err_Load
strDisplayName = Form1.NTService1.DisplayName
If Command = "-install" Then
' Enable interaction with desktop.
Form1.NTService1.Interactive = True
If Form1.NTService1.Install Then
MsgBox strDisplayName & " installed successfully"
Else
MsgBox strDisplayName & " failed to install"
End If
End
ElseIf Command = "-uninstall" Then
If Form1.NTService1.Uninstall Then
MsgBox strDisplayName & " uninstalled successfully"
Else
MsgBox strDisplayName & " failed to uninstall"
End If
End
ElseIf Command = "-debug" Then
Form1.NTService1.Debug = True
ElseIf Command <> "" Then
MsgBox "Invalid command option"
End
End If
' Connect service to Windows NT services controller.
Form1.NTService1.StartService
Err_Load:
' Error starting service
End Sub
Private Sub NTService1_Start(Success As Boolean)
On Error GoTo Err_Start
SC_HANDLE OpenSCManager(
LPCTSTR lpMachineName, // pointer to machine name string
LPCTSTR lpDatabaseName, // pointer to database name string
DWORD dwDesiredAccess // type of access
);
SC_HANDLE CreateService(
SC_HANDLE hSCManager, // handle to service control manager
// database
LPCTSTR lpServiceName, // pointer to name of service to start
LPCTSTR lpDisplayName, // pointer to display name
DWORD dwDesiredAccess, // type of access to service
DWORD dwServiceType, // type of service
DWORD dwStartType, // when to start service
DWORD dwErrorControl, // severity if service fails to start
LPCTSTR lpBinaryPathName, // pointer to name of binary file
LPCTSTR lpLoadOrderGroup, // pointer to name of load ordering
// group
LPDWORD lpdwTagId, // pointer to variable to get tag identifier
LPCTSTR lpDependencies, // pointer to array of dependency names
LPCTSTR lpServiceStartName,
// pointer to account name of service
LPCTSTR lpPassword // pointer to password for service account
);
SC_HANDLE OpenService(
SC_HANDLE hSCManager, // handle to service control manager
// database
LPCTSTR lpServiceName, // pointer to name of service to start
DWORD dwDesiredAccess // type of access to service
);
BOOL DeleteService(
SC_HANDLE hService // handle to service
);
BOOL StartServiceCtrlDispatcher(
LPSERVICE_TABLE_ENTRY lpServiceStartTable // address of service
// table
);
BOOL SetServiceStatus(
SERVICE_STATUS_HANDLE hServiceStatus~,
// service status handle
LPSERVICE_STATUS lpServiceStatus // address of status structure
);