本帖最后由 Ycxw2008 于 2012-1-21 12:09 编辑 Local $PCNAME=InputBox('提示','请输入电脑名'),$ServerName=InputBox('提示','请输入服务名')
;为了方便你测试,如果测试成功可以不用InputBox,直接按下面格式
;$Pcname='PC',
;$ServerName='WSearch'
;简单测试了下,是需要服务的短名称);WSearch=Windows Search
If $PcName='' Or $ServerName='' Then
MsgBox(0,'警告','缺少必须变量')
exit
Endif
If _ServiceExists($PCNAME,$ServerName) Then
MsgBox(0, '', '继续卸载');可以执行卸载程序
Else
Exit;不存在则退出
EndIf
Func _ServiceExists($sComputerName, $sServiceName)
Local $hAdvapi32
Local $arRet
Local $hSC
Local $bExist = 0
$hAdvapi32 = DllOpen("advapi32.dll")
If $hAdvapi32 = -1 Then Return 0
$arRet = DllCall($hAdvapi32, "long", "OpenSCManager", _
"str", $sComputerName, _
"str", "ServicesActive", _
"long", 0x0001)
If $arRet[0] <> 0 Then
$hSC = $arRet[0]
$arRet = DllCall($hAdvapi32, "long", "OpenService", _
"long", $hSC, _
"str", $sServiceName, _
"long", 0x0080)
If $arRet[0] <> 0 Then
$bExist = 1
DllCall($hAdvapi32, "int", "CloseServiceHandle", "long", $arRet[0])
EndIf
DllCall($hAdvapi32, "int", "CloseServiceHandle", "long", $hSC)
EndIf
DllClose($hAdvapi32)
Return $bExist
EndFunc ;==>_ServiceExist
上面函数也是Copy"ServiceControl.au3"里的 只是让你更好理解
再有需求请自行打开ServiceControl.au3研究,找不到就everything搜 |