|
在论坛上看了P版的注册成服务的例子到是可以用。但是如何在安装服务时一同修改服务的属性呢?就是“恢复”里的项目。
Const $Lsa_AdvApi32 = DllOpen("AdvApi32.dll")
Const $Lsa_Kernel32 = DllOpen("Kernel32.dll")
_CreateService("73", "A73", BitOR("0x0010", "0x0100"), 3, "0x00000000", @ScriptFullPath, "", 1)
; 服务名 显示名
Func _CreateService($sServiceName, $sDisplayName, $iServiceType, $iStartType, $iErrorControl, $sBinaryPath, $sLoadOrderGroup, $aDependencies, $sStartName = "", $sPassword = "", $iDesiredAccess = 0xF01FF)
Local $iResult, $tServiceName, $tDisplayName, $tBinaryPath, $hSC, $tLoadOrder, $tDependencies, $tStartName, $tPassword, $sBuffer
$tServiceName = DllStructCreate("wchar ServiceName[" & StringLen($sServiceName) + 1 & "]")
DllStructSetData($tServiceName, "ServiceName", $sServiceName)
If $sDisplayName <> "" Then
$tDisplayName = DllStructCreate("wchar DisplayName[" & StringLen($sDisplayName) + 1 & "]")
DllStructSetData($tDisplayName, "DisplayName", $sDisplayName)
EndIf
If $sBinaryPath <> "" Then
$tBinaryPath = DllStructCreate("wchar BinaryPath[" & StringLen($sBinaryPath) + 1 & "]")
DllStructSetData($tBinaryPath, "BinaryPath", $sBinaryPath)
EndIf
If $sLoadOrderGroup <> "" Then
$tLoadOrder = DllStructCreate("wchar LoadOrder[" & StringLen($sLoadOrderGroup) + 1 & "]")
DllStructSetData($tLoadOrder, "LoadOrder", $sLoadOrderGroup)
EndIf
If $sStartName <> "" Then
$tStartName = DllStructCreate("wchar StartName[" & StringLen($sStartName) + 1 & "]")
DllStructSetData($tStartName, "StartName", $sStartName)
EndIf
If $sPassword <> "" Then
$tPassword = DllStructCreate("wchar Password[" & StringLen($sPassword) + 1 & "]")
DllStructSetData($tPassword, "Password", $sPassword)
EndIf
If IsArray($aDependencies) And UBound($aDependencies, 0) = 1 Then
For $i = 0 To UBound($aDependencies) - 1
$sBuffer &= ("wchar[" & StringLen($aDependencies[$i]) + 1 & "];")
Next
$tDependencies = DllStructCreate($sBuffer & ";wchar[1]")
For $i = 0 To UBound($aDependencies) - 1
DllStructSetData($tDependencies, ($i + 1), $aDependencies[$i])
Next
EndIf
$hSC = _LsaOpenSCManager("", 2)
$iResult = DllCall("AdvApi32.dll", "hWnd", "CreateServiceW", _
"hWnd", $hSC, _
"ptr", DllStructGetPtr($tServiceName), _
"ptr", DllStructGetPtr($tDisplayName), _
"dword", $iDesiredAccess, _
"dword", $iServiceType, _
"dword", $iStartType, _
"dword", $iErrorControl, _
"ptr", DllStructGetPtr($tBinaryPath), _
"ptr", DllStructGetPtr($tLoadOrder), _
"ptr", 0, _
"ptr", DllStructGetPtr($tDependencies), _
"ptr", DllStructGetPtr($tStartName), _
"ptr", DllStructGetPtr($tPassword))
Return SetError(_GetLastError(), _LsaCloseServiceHandle($hSC), $iResult[0])
EndFunc ;==>_CreateService
Func _LsaOpenSCManager($sSystem = "", $iAccessMask = 0xF003F)
Local $hSC
$hSC = DllCall($Lsa_AdvApi32, "hWnd", "OpenSCManager", "str", $sSystem, "str", "ServicesActive", "dword", $iAccessMask)
Return SetError(_GetLastError(), 0, $hSC[0])
EndFunc ;==>_LsaOpenSCManager
Func _GetLastError()
Local $iSysError = DllCall($Lsa_Kernel32, "long", "GetLastError")
Return $iSysError[0]
EndFunc ;==>_GetLastError
Func _LsaCloseServiceHandle($hService)
Local $iResult = DllCall($Lsa_AdvApi32, "int", "CloseServiceHandle", "hWnd", $hService)
Return SetError(_GetLastError(), 0, $iResult[0] <> 0)
EndFunc ;==>_LsaCloseServiceHandle |
|