troubleshooting Question

VB Script to pull the list of services running and the version of its executables.

Avatar of sujithmd
sujithmdFlag for India asked on
Microsoft Legacy OSVB Script
2 Comments1 Solution543 ViewsLast Modified:
Hi Scripting Gurus I've wrote a script to pull the list of services running on a list of servers and export the details to a csv file with the service name service status and service executables file version.

Problem is that some executable paths have some switches and in those scenario script is unable to pull the exe's file version see some samples below. How to pull the file information as well in the script.

C:\Windows\System32\svchost.exe -k LocalSystemNetworkRestricted      
C:\Windows\System32\svchost.exe -k LocalServiceNetworkRestricted      
C:\Windows\system32\svchost.exe -k AxInstSVGroup      
C:\Program Files\Microsoft Forefront Identity Manager\2010\Password Reset Client Service\PwdMgmtProxy.exe""      
C:\Program Files (x86)\Common Files\Macrovision Shared\FLEXnet Publisher\FNPLicensingService.exe""      

On Error Resume Next
Dim fso, ts
strOutput = "Service_Status.csv"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set input = fso.OpenTextFile("servers.txt", 1, False)
Set ts = fso.CreateTextFile("Service_Status.csv")
fv = "File Version"
ts.WriteLine """Computer"",""Service Name"",""Service State"",""Executable Path"",""File Version"""

While Not input.AtEndOfStream
	strComputer = input.ReadLine
	Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")

For Each objService in colRunningServices 
	    ts.WriteLine """" & strComputer & """,""" & objService.DisplayName & """,""" & objService.State & """,""" & objService.PathName & """,""" & objFSO.GetFileVersion(objService.PathName) & """"
If Err.Number <>0  Then 
	    ts.WriteLine """" & strComputer & """,""" & objService.DisplayName & """,""" & objService.State & """,""" & objService.PathName & """"
	    End If 

Set ts = Nothing
Set fso = Nothing

MsgBox "Done. Please see " & strOutput
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros