Windows – Checking file properties in a batch script

batchbatch-filescriptingwindowswindows-vista

I have a batch file from a vendor to patch some software on a Vista machine. I'm going to be using GPO to push it out as a startup script.

My problem is some systems require this software and some don't.

I'd like to add code to the beginning of the script to look for the existence of an exe, and pull the string that's viewable if you right click the exe, details tab, "Product version" field.

Please suggest other solutions as comments. I know about other ways to handle this and have a couple lined up. I'm open to suggestions but would prefer all answers be to this specific question. Can it be done, if yes, how?

Thanks!
-Mathew

Best Answer

You're going to need a utility called filever which ships as a support tool with Windows. Here's a page detailing it's options.

In a batch file you would likely use it like this:

@IF NOT EXIST C:\PATH\TO\YOUR\APP.EXE GOTO END
@SET APPVER=3.14159
@\\FILESHARE\filever.exe "C:\PATH\TO\YOUR\APP.EXE" | findstr /i %APPVER% > nul
@IF %ERRORLEVEL% EQU 0 GOTO END
@\\FILESHARE\PATH\TO\YOUR\APP\Update.exe
:END
  • The first line checks for the existance of your application.
  • The second line sets the version number you want to patch to
  • The third line utilizes the filever tool from MS and the built-in findstr tool to determine what version they are currently running and compare it to the version you want them to run
  • The fourth line tells them to skip running Update.exe if they are already at the correct version
  • The fifth line runs the update for people who need to be patched
  • The last line is the GOTO point referenced above and ends the batch