标签归档:服务管理

创建删除服务

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

继续阅读

Scripts to manage Services

Changing a Service Account Password

Changes the service account password for any services running under the hypothetical service account Netsvc.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service")
For Each objservice in colServiceList
    If objService.Startname = ".\netsvc" Then
        errReturn = objService.Change( , , , , , , , "password")  
    End If 
Next

继续阅读