Script to find state of service on remote computers

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
yalgaar
Posts: 4
Joined: 09 Oct 2008 15:44

Script to find state of service on remote computers

#1 Post by yalgaar » 11 May 2009 14:58

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)

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

#2 Post by Batcher » 12 May 2009 01:36

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

Post Reply