2

WMI: VBscript to enumerate all services and their status on a computer

Posted February 3rd, 2010 in services and tagged , , , , , , by dirk adamsky

The script for today is a wmi script.
The script creates a list of all services on a computer and also displays the status of the services.
Default computer is the local machine.
When the dot is replaced by another machine name the script works against that machine.
There are some conditions that must be met:

  1. the script must be run with administrative credentials
  2. the firewall of the remote machine needs the following ports opened for WMI: TCP 135, TCP 4168 and
    UDP 9256

Follow the next steps to make and run the script (admin rights needed):

  • open your favorite text editor (mine is notepad++)
  • copy and paste the script into the editor (delete the line numbers)
  • save the script (for example c:\templistservices.vbs)
  • open a command prompt
  • go to “c:\temp”
  • give “cscript listservices.vbs” (without quotes) and enter

The script:

' Name : listservices.vbs
' Description : script to enumerate all services and their status on a computer
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 03-02-2010
' Level : beginner

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "rootcimv2")
Set objListOfServices = objWMIService.ExecQuery("Select * from Win32_Service ")
For Each objService in objListOfServices
	Wscript.Echo objService.name & " ;  " & objService.State
Next
Set colListOfServices = Nothing
Set objWMIService = Nothing

As said earlier: when you have questions/problems please give a reply.

Happy scripting.

Best regards,

Dirk Adamsky – Deludi BV


Related Posts:
  • VBscript and WMI: VBscript to find files with specific extensions and creation date on remote servers
  • Active Directory and WMI: VBscript to enumerate the ntfs rights of a given UNC path and a given level of subfolders
  • Active Directory and WMI: VBscript to enumerate the ntfs rights of a given UNC path

  • 2 Responses so far.

    1. Ben Penney says:

      Line 9 has had multiple slashes removed.

      Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\” & strComputer & “rootcimv2″)

      should read

      Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2″)

    2. dirk adamsky says:

      Hi Ben,

      sorry for my late reply (was busy with other projects).
      You are right.
      I corrected the script.
      The cause of the lost slashes is a copy of the script codes and articles from my previous script blog to vbscriptblog.com.
      During the backup and restore a lot of slashes got lost.
      happy scripting.

      Best regards,

      Dirk Adamsky

    Leave a Reply