简体   繁体   中英

How to start stop Windows Services using Scripting Language like Vb Script or something?

I Just want to manage Windows Services through Scripting languages( VB Script or Something ). Like Starting, stopping, Getting the status, Checking the dependencies etc. Please help with Code snippets or URL referances.

Use this script to start a service:

'' Starts service 'strService' on computer named 'strComputer'
''
Sub StartService(strService, strComputer)
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" _
       & strComputer & "\root\cimv2")
    Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strService & "'")
    For Each objService in colListOfServices
       objService.StartService
    Next
End Sub

'' Start Windows CardSpace service on local host:
StartService "idsvc", "."

Instead of StartService , you can use StopService to stop the service. See this MSDN article for other useful methods of Win32_Service .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM