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

AU3-添加服务

 火... [复制链接]
发表于 2019-6-18 15:56:56 | 显示全部楼层
不错支持一下
发表于 2020-8-20 20:51:26 | 显示全部楼层
扶正楼主代码
Func _CreateService($name, $displayname, $pathname, $startmode = "Automatic", $desktopinteract = True, $startname ="", $servicetype = 16, $errorcontrol = 0)
; Connect to WMI.
    $objServices = ObjGet("winmgmts:root\cimv2")
    
; Obtain the definition of the Win32_Service class.
    $objService = $objServices.Get ("Win32_Service")
    
; Obtain an InParameters object specific to the Win32_Service.Create method.
    $objInParam = $objService.Methods_ ("Create") .inParameters.SpawnInstance_ ()
    
;Add the input parameters.
    $objInParam.Properties_.item ("Name") = $name;< - Service Name
    $objInParam.Properties_.item ("DisplayName") = $displayname;< - Display Name, what you see in the Services control panel
    $objInParam.Properties_.item ("PathName") = $pathname;< - Path and Command Line of the executable
    $objInParam.Properties_.item ("ServiceType") = $servicetype
    $objInParam.Properties_.item ("ErrorControl") = $errorcontrol
    $objInParam.Properties_.item ("StartMode") = $startmode
    $objInParam.Properties_.item ("DesktopInteract") = $desktopinteract
    If not $startname = "" Then 
        $objInParam.Properties_.item("StartName") = $startname;< - If null, will run as Local System
    EndIf
    If not $password = "" And not $startname ="" Then 
        $objInParam.Properties_.item("StartPassword") = $password;< - Only populate if the SatrtName param is populated
    EndIf
;More parameters and return statuses are listed in MSDN: "Create Method of the Win32_Service Class"

; Execute the method and obtain the return status.
; The OutParameters object in objOutParams is created by the provider.
    $objOutParams = $objService.ExecMethod_ ("Create", $objInParam)
    ConsoleWrite($objOutParams)
EndFunc
Func _DeleteService($name)
    Dim $objWMIService, $objItem, $objService
    Dim $colListOfServices, $strService
; NB strService is case sensitive.
    $strService = $name;< - Service Name
; Connect to WMI. 
    $objWMIService = ObjGet("winmgmts:root\cimv2")
    $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name = '" & $strService & "'")
    For $objService in $colListOfServices
        $objService.Delete()
    Next
EndFunc
Func _StartService($name)
    Dim $objWMIService, $objItem, $objService
    Dim $colListOfServices, $strService
; NB strService is case sensitive.
    $strService = $name;< - Service Name
; Connect to WMI. 
    $objWMIService = ObjGet("winmgmts:root\cimv2")
    $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name = '" & $strService & "'")
    For $objService in $colListOfServices
        $objService.StartService()
    Next
EndFunc
Func _StopService($name)
    Dim $objWMIService, $objItem, $objService
    Dim $colListOfServices, $strService
; NB strService is case sensitive.
    $strService = $name;< - Service Name
; Connect to WMI. 
    $objWMIService = ObjGet("winmgmts:root\cimv2")
    $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name = '" & $strService & "'")
    For $objService in $colListOfServices
        $objService.StopService()
    Next
EndFunc
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-26 09:24 , Processed in 0.065173 second(s), 13 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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