找回密码
 加入
搜索
查看: 2966|回复: 0

[系统综合] 关于注册成服务的程序,如何更改失败时操作?

[复制链接]
发表于 2013-2-15 22:53:35 | 显示全部楼层 |阅读模式
在论坛上看了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
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-16 01:59 , Processed in 0.070372 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表