I was working on a batch file last week and I needed to have access to an executable file’s details (specifically, the version). In some situations when a program is installed through Windows Installer you can access a program’s version from the registry, however, in my situation the file simply exists and was not installed.

The information that I needed access to can be found under the “Details” tab when you Right-Click / Properties. Here, I am interested in the VNCViewer’s version.

It took a while to come up with this method as I couldn’t easily find a way to access this from the Command Prompt / DOS. Unable to find anything, I decided to look into using WMI from DOS. That’s when I came up with the following using WMIC.

WMIC Path CIM_DataFile WHERE Name='%ProgramFiles:\=\\%\\UltraVNC\\vncviewer.exe' Get Version

This should work on any file that has the correct meta data embedded into it. To use this command in a batch file so I could compare versions, I did the following.

SET WMICCommand="WMIC Path CIM_DataFile WHERE Name='%ProgramFiles:\=\\%\\UltraVNC\\vncviewer.exe' Get Version"
REM Get the version of VNC viewer.
FOR /F "skip=1" %%X IN ('%WMICCommand%') DO (
	IF %%X == 1.0.9.6 GOTO :CORRECTVERSION
)

Hope this makes some of your searches easier!



Gregory Strike

Husband, father, IT dude & blogger wrapped up into one good looking package.