开发者

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

开发者 https://www.devze.com 2023-01-17 16:44 出处:网络
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 w

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消