Function DeleteService(SrvName) strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colListOfServices = objWMIService.ExecQuery _ ("Select * from Win32_Service Where Name = '" & SrvName & "'") For Each objService in colListOfServices objService.StopService() objService.Delete() Next If Err.Number <> 0 Then DeleteService = 0 Else DeleteService = 1 End If End Function Sub InstallService(SrvName,DispName,Path) Const OWN_PROCESS = 16 Const NOT_INTERACTIVE = False Const NORMAL_ERROR_CONTROL = 2 strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objService = objWMIService.Get("Win32_Service") errReturn = objService.Create(SrvName,DispName, _ Path, OWN_PROCESS, NORMAL_ERROR_CONTROL,_ "Automatic", NOT_INTERACTIVE, "LocalSystem", "" ) End Sub
创建删除服务
发表评论