Page 1 of 1

Script to find state of service on remote computers

Posted: 11 May 2009 14:58
by yalgaar
Can you help me write a script that will tell me if the "Windows Update" service on a several remote computers (list of IP addresses in notepad)

Posted: 12 May 2009 01:36
by Batcher
test.vbs

Code: Select all

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSrcFile = objFSO.OpenTextFile("IPlist.txt",1,True)

Do Until objSrcFile.AtEndOfStream
  strComputer = objSrcFile.ReadLine
  If strComputer <> "" Then
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colRunningServices = objWMIService.ExecQuery ("Select * from Win32_Service Where DisplayName = 'Windows Update'")
    For Each objService in colRunningServices
      If objService.State <> "Running" Then
        Wscript.Echo "The service is not running"
      else
        Wscript.Echo "The service is running"
      End If
    Next
  End If
Loop