1

Can someone please help me figure out the code for Windows batch file that will look a the properties of executables or installers in a directory, determine the version of the installer and the name of the product, store them in variables, and query agaist installed products in the registry? The idea is that I would like to copy updates to a folder on a machine that has no internet connection from disc. From there I would like to execute a batch file that looks at the version and name of software, stores them in variables, then queries the registry to see if there is a previous version installed. So, if I had downloaded install_flash_player_ax.exe, it should know to look in the registry for adobe flashplayer. If the version on the executable is newer than the version in the registry, it would do a quiet install.

Any help or suggestions would be greatly appreciated!

john3j04
  • 11
  • 2

1 Answers1

0

Though it is an old question, I'd try to answer it, as it may be useful for the others. Windows command shell doesn't have a straight way to get file metadata like version but you can use wmic for it. The main problem is that the display name of the software may be different in the properties of the installation/update exe file and than the one in the registry. So it is a bad idea to take the name from the file metadata and query for it in whole HKLM registry hive. Also, if you do not have a predefined list of the software to be updated and do not know the exact path in the registry where version for each of them is stored, the idea to loop against the list of exe to get names from their metadata id also bad.

So, the best way to search for that is to make a script for each exe separately and to add them to Windows scheduler. Here is an example of the required batch script to automate updates for Adobe Flash Player for 64-bit OS:

@echo off
for /f %%a in ('wmic datafile where name^="C:\\Users\\username\\Downloads\\install_flash_player_19_active_x.exe" get version ^| find /n /v "" ^| findstr "^\[2\]"') do set var=%%a
for /f "tokens=2 delims=]" %%a in ("%var%") do set prver=%%a
echo Available version: %prver%
for /f "tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{EE56217C-B3F9-402B-B4EC-63F090F51D3D}" /v DisplayVersion') do set regversion=%%a
echo Installed version: %regversion%
if %prver% == %regversion% (echo The newest version %regversion% installed) else (echo Update required & "C:\Users\username\Downloads\install_flash_player_19_active_x.exe")

Update file is located in some local folder, in my case C:\Users\username\Downloads\install_flash_player_19_active_x.exe. When programs are installed, they register themselves in HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ for 64-bot OS and HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ for 32-bit.

Hence, you need to find the path for every installation you need. Please note that {EE56217C-B3F9-402B-B4EC-63F090F51D3D} in my script is the GUID for the given version of Flash Player 19.

Here is the same in PowerShell which is more elegant:

$filever = (Get-Item "C:\Users\username\Downloads\install_flash_player_19_active_x.exe").versioninfo.fileversion
$appname = (Get-Item "C:\Users\username\Downloads\install_flash_player_19_active_x.exe").versioninfo.internalname
$regpath = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{EE56217C-B3F9-402B-B4EC-63F090F51D3D}"
$regversion = Get-ItemProperty $regpath -Name "DisplayVersion" | select -ExpandProperty "DisplayVersion"
if ($winrarreg -eq $regversion) {
    "The newest version of Flash Player $regpath is already installed"
    } else {
        "Current installed version is:" +  $regversion
        "Available version is:" + $filever
        "Let's update Flash Player"
        Start-Process -FilePath "C:\Users\username\Downloads\install_flash_player_19_active_x.exe"
    }
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
Hardoman
  • 254
  • 1
  • 13