找回密码
 加入
搜索
楼主: autoit

AU3-添加服务

 火... [复制链接]
发表于 2019-6-18 15:56:56 | 显示全部楼层
不错支持一下
发表于 2020-8-20 20:51:26 | 显示全部楼层
扶正楼主代码

  1. Func _CreateService($name, $displayname, $pathname, $startmode = "Automatic", $desktopinteract = True, $startname ="", $servicetype = 16, $errorcontrol = 0)
  2. ; Connect to WMI.
  3.     $objServices = ObjGet("winmgmts:root\cimv2")
  4.    
  5. ; Obtain the definition of the Win32_Service class.
  6.     $objService = $objServices.Get ("Win32_Service")
  7.    
  8. ; Obtain an InParameters object specific to the Win32_Service.Create method.
  9.     $objInParam = $objService.Methods_ ("Create") .inParameters.SpawnInstance_ ()
  10.    
  11. ;Add the input parameters.
  12.     $objInParam.Properties_.item ("Name") = $name;< - Service Name
  13.     $objInParam.Properties_.item ("DisplayName") = $displayname;< - Display Name, what you see in the Services control panel
  14.     $objInParam.Properties_.item ("PathName") = $pathname;< - Path and Command Line of the executable
  15.     $objInParam.Properties_.item ("ServiceType") = $servicetype
  16.     $objInParam.Properties_.item ("ErrorControl") = $errorcontrol
  17.     $objInParam.Properties_.item ("StartMode") = $startmode
  18.     $objInParam.Properties_.item ("DesktopInteract") = $desktopinteract
  19.     If not $startname = "" Then
  20.         $objInParam.Properties_.item("StartName") = $startname;< - If null, will run as Local System
  21.     EndIf
  22.     If not $password = "" And not $startname ="" Then
  23.         $objInParam.Properties_.item("StartPassword") = $password;< - Only populate if the SatrtName param is populated
  24.     EndIf
  25. ;More parameters and return statuses are listed in MSDN: "Create Method of the Win32_Service Class"

  26. ; Execute the method and obtain the return status.
  27. ; The OutParameters object in objOutParams is created by the provider.
  28.     $objOutParams = $objService.ExecMethod_ ("Create", $objInParam)
  29.     ConsoleWrite($objOutParams)
  30. EndFunc
  31. Func _DeleteService($name)
  32.     Dim $objWMIService, $objItem, $objService
  33.     Dim $colListOfServices, $strService
  34. ; NB strService is case sensitive.
  35.     $strService = $name;< - Service Name
  36. ; Connect to WMI.
  37.     $objWMIService = ObjGet("winmgmts:root\cimv2")
  38.     $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name = '" & $strService & "'")
  39.     For $objService in $colListOfServices
  40.         $objService.Delete()
  41.     Next
  42. EndFunc
  43. Func _StartService($name)
  44.     Dim $objWMIService, $objItem, $objService
  45.     Dim $colListOfServices, $strService
  46. ; NB strService is case sensitive.
  47.     $strService = $name;< - Service Name
  48. ; Connect to WMI.
  49.     $objWMIService = ObjGet("winmgmts:root\cimv2")
  50.     $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name = '" & $strService & "'")
  51.     For $objService in $colListOfServices
  52.         $objService.StartService()
  53.     Next
  54. EndFunc
  55. Func _StopService($name)
  56.     Dim $objWMIService, $objItem, $objService
  57.     Dim $colListOfServices, $strService
  58. ; NB strService is case sensitive.
  59.     $strService = $name;< - Service Name
  60. ; Connect to WMI.
  61.     $objWMIService = ObjGet("winmgmts:root\cimv2")
  62.     $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name = '" & $strService & "'")
  63.     For $objService in $colListOfServices
  64.         $objService.StopService()
  65.     Next
  66. EndFunc
复制代码
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2026-9-23 14:14 , Processed in 0.046525 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

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