Wednesday, October 20, 2010

WSH - Stop, Start service

strState = ""
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name='Themes' ")
For Each objService in colRunningServices
    Wscript.Echo objService.DisplayName  & VbTab & objService.State
  If objService.DisplayName = "Themes" Then
  If objService.State = " Running" Then
          errReturnCode = objService.StopService()
  Else
   errReturnCode = objService.StartService()
   End If
 End

No comments:

Post a Comment

 

©2010 Software Testing powered by Free Blogger Templates | Author : Anand Satish