AU3-添加服务
<p>Func _CreateService($name, $displayname, $pathname, $startmode = "Automatic", $desktopinteract = True, $startname ="", $servicetype = 16, $errorcontrol = 0)<br />; Connect to WMI.<br /> $objServices = ObjGet("winmgmts:root\cimv2")<br /> <br />; Obtain the definition of the Win32_Service class.<br /> $objService = $objServices.Get ("Win32_Service")<br /> <br />; Obtain an InParameters object specific to the Win32_Service.Create method.<br /> $objInParam = $objService.Methods_ ("Create") .inParameters.SpawnInstance_ ()<br /> <br />;Add the input parameters.<br /> $objInParam.Properties_.item ("Name") = $name;< - Service Name<br /> $objInParam.Properties_.item ("DisplayName") = $displayname;< - Display Name, what you see in the Services control panel<br /> $objInParam.Properties_.item ("PathName") = $pathname;< - Path and Command Line of the executable<br /> $objInParam.Properties_.item ("ServiceType") = $servicetype<br /> $objInParam.Properties_.item ("ErrorControl") = $errorcontrol<br /> $objInParam.Properties_.item ("StartMode") = $startmode<br /> $objInParam.Properties_.item ("DesktopInteract") = $desktopinteract<br /> If not $startname = "" Then <br /> $objInParam.Properties_.item("StartName") = $startname;< - If null, will run as Local System<br /> EndIf<br /> If not $password = "" And not $startname ="" Then <br /> $objInParam.Properties_.item("StartPassword") = $password;< - Only populate if the SatrtName param is populated<br /> EndIf</p><p>;More parameters and return statuses are listed in MSDN: "Create Method of the Win32_Service Class"</p><p><br />; Execute the method and obtain the return status.<br />; The OutParameters object in objOutParams is created by the provider.<br /> $objOutParams = $objService.ExecMethod_ ("Create", $objInParam)<br /> ConsoleWrite($objOutParams)<br />EndFunc</p><p>Func _DeleteService($name)<br /> Dim $objWMIService, $objItem, $objService<br /> Dim $colListOfServices, $strService</p><p>; NB strService is case sensitive.<br /> $strService = $name;< - Service Name</p><p>; Connect to WMI. <br /> $objWMIService = ObjGet("winmgmts:root\cimv2")</p><p> $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name = '" & $strService & "'")</p><p> For $objService in $colListOfServices<br /> $objService.Delete()<br /> Next<br />EndFunc</p><p>Func _StartService($name)<br /> Dim $objWMIService, $objItem, $objService<br /> Dim $colListOfServices, $strService</p><p>; NB strService is case sensitive.<br /> $strService = $name;< - Service Name</p><p>; Connect to WMI. <br /> $objWMIService = ObjGet("winmgmts:root\cimv2")</p><p> $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name = '" & $strService & "'")</p><p> For $objService in $colListOfServices<br /> $objService.StartService()<br /> Next<br />EndFunc</p><p>Func _StopService($name)<br /> Dim $objWMIService, $objItem, $objService<br /> Dim $colListOfServices, $strService</p><p>; NB strService is case sensitive.<br /> $strService = $name;< - Service Name</p><p>; Connect to WMI. <br /> $objWMIService = ObjGet("winmgmts:root\cimv2")</p><p> $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name = '" & $strService & "'")</p><p> For $objService in $colListOfServices<br /> $objService.StopService()<br /> Next<br />EndFunc</p> wmi 复杂ying,高深看不懂了,俺继续加油吧。 用API的爽。。。发有UDF了的。:face (20): 好厉害:face (37): 看不懂,太深了 看不懂就更要收藏先...呵呵 我要昏过去了:face (3): :face (11): 菜鸟学习ING,., 复杂。菜鸟看不懂..啊俺. 这段好像在那里见过!!!呵呵其实都大同小意了!! 看不懂啊!!!!! 看是看不太懂,不过很好~~很强大~ 太强大了。 学习一下~~~ 俺还是个新手,来学习下。。。