Getting version of running services?

Hi All,

I need to get the version of certain services running in our SOE and have been using the relevance of version of file of service “MyService” . This works for the most part, however for those that don’t I have been just going to the executable of the service directly using version of file “X;\path\to\MyService.exe”. This works for all except one SOE component as the installation path of the service over the years has been anything but standard. I started using an something like the following;

if (exists file  "X;\path\to\MyService.exe") 
	then ((version of file   "X;\path\to\MyService.exe") as string)   
	else (  if (exists file  "X;\path\to\other\MyService.exe") 
	then ((version of file   "X;\path\to\other\MyService.exe") as string)   
	else  "Undetermined")

This is quickly growing though with the number of different install paths. As I spend only small part of my time in Bigfix, just wondering if there is a smarter way I can do this that ideally works on everything from Windows 2000 (yes, I know) through to Windows 2012?

Thanks for any help.

image path of service "X" will give you the path of the service’s executable. You may be able to use that, but you might get complexities of the image path contains command-line parameters you need to parse (for instance, if the service is actually running out of svchost.exe).

On my system I found that the “PerfHost” service itself did not return a version, but the image path of it did. Here is what seems to work for me, to use “version of service” if possible, then “version of image path of service” if possible, and handling image paths with quotes; it doesn’t yet handle unquoted service paths with a command line parameter, but should be extendable to that if needed -

(if exists version of it then version of it as string else (if exists file (it) whose (exists version of it) then version of file (it) as string else "unknown") of ((if it contains "%22" then preceding text of first "%22" of following text of first "%22" of it else it) of image path of it))of services ("PerfHost")

1 Like

This one should handle spaces as well, but note how everything running out of ServiceHost shows the same version number (the version of svchost.exe) -

q: (service name of it, image path of it, ((if exists version of it then version of it as string  else (if exists file (it) whose (exists version of it) then version of file (it) as string else "na") of ((if it contains "%22" then preceding text of first "%22" of following text of first "%22" of it else if it contains " " then preceding text of first " " of it else it) of image path of it))))of services 
A: AdobeARMservice, "C:\Program Files (x86)\Common Files\Adobe\ARM\1.0\armsvc.exe", 1.824.20.5020
A: AJRouter, C:\WINDOWS\system32\svchost.exe -k LocalServiceNetworkRestricted, 10.0.14393.0
A: ALG, C:\WINDOWS\System32\alg.exe, na
A: AppIDSvc, C:\WINDOWS\system32\svchost.exe -k LocalServiceNetworkRestricted, 10.0.14393.0
A: Appinfo, C:\WINDOWS\system32\svchost.exe -k netsvcs, 10.0.14393.0
A: AppReadiness, C:\WINDOWS\System32\svchost.exe -k AppReadiness, 10.0.14393.0
A: AppXSvc, C:\WINDOWS\system32\svchost.exe -k wsappx, 10.0.14393.0
A: AudioEndpointBuilder, C:\WINDOWS\System32\svchost.exe -k LocalSystemNetworkRestricted, 10.0.14393.0
A: Audiosrv, C:\WINDOWS\System32\svchost.exe -k LocalServiceNetworkRestricted, 10.0.14393.0
1 Like

Sorry for delay in getting back to this. Thanks for your assistance Jason, using your analysis and it is working MUCH better for me.