Skip to main content

How to Check if a Program Version is Installed in Batch Script

In a professional IT environment, simply knowing a program is "Installed" isn't enough. You need to know which Version is running. If your team is using an outdated version of a web browser or a security tool, they are vulnerable to bugs and security exploits. Manual version checking is impossible to scale. A Batch script can use WMIC to query the system's software inventory and compare the current version number against your corporate requirements. This allows for "Version-Aware" automation where a script can skip the installation if the correct version is already present, or trigger an update if it detects an older one.

This guide will explain how to audit software versions via the command line.

Method: The Precise Version Check (WMIC)

The wmic product command allows you to filter by name and extract the exact version string.

info

Performance Note. The wmic product command enumerates every MSI-installed product on the system, which can take several minutes. For faster alternatives, see the registry approach in the "Common Errors" section.

@echo off
setlocal enabledelayedexpansion

set "AppName=Google Chrome"
set "ReqVersion=120.0.6099.130"

echo [AUDIT] Checking version for %AppName%...
echo This may take a moment while Windows enumerates products...

:: Clear any stale value
set "CurrVersion="

:: Extract only the version string
for /f "tokens=2 delims==" %%v in ('wmic product where "Name='%AppName%'" get Version /value 2^>nul ^| findstr "="') do (
set "CurrVersion=%%v"
)

:: Remove hidden carriage return characters from WMIC output
if defined CurrVersion (
for /f "tokens=*" %%c in ("!CurrVersion!") do set "CurrVersion=%%c"
)

if not defined CurrVersion (
echo [ALERT] %AppName% is NOT INSTALLED.
) else (
echo [FOUND] %AppName% Version: !CurrVersion!

if /i "!CurrVersion!"=="%ReqVersion%" (
echo [OK] Version is up to date.
) else (
echo [UPDATE] Version mismatch detected.
echo Required: %ReqVersion%
echo Installed: !CurrVersion!
)
)

pause
endlocal

Method 2: Fast Version Check (Registry)

For speed-critical scripts, querying the registry directly is nearly instant compared to wmic product.

@echo off
setlocal enabledelayedexpansion

set "AppName=Google Chrome"
set "DisplayVersion="

echo [SCAN] Searching registry for %AppName%...

:: Search both 64-bit and 32-bit uninstall registry locations
for %%R in (
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
"HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
) do (
for /f "tokens=2*" %%a in ('reg query %%R /s /v "DisplayName" 2^>nul ^| findstr /i "%AppName%"') do (
:: Found a match - now get the version from the same key
for /f "tokens=2*" %%x in ('reg query %%R /s /v "DisplayVersion" 2^>nul ^| findstr /i "DisplayVersion"') do (
if not defined DisplayVersion set "DisplayVersion=%%y"
)
)
)

if not defined DisplayVersion (
echo [ALERT] %AppName% was not found in the registry.
) else (
echo [FOUND] %AppName% Version: !DisplayVersion!
)

pause
endlocal

Method 3: The "Installation Gate" (Skip if Current)

Use this in a setup script to avoid wasting time re-installing software that is already at the required version.

@echo off
setlocal enabledelayedexpansion

set "AppName=7-Zip"
set "ReqVersion=23.01"
set "Installer=C:\Deploy\7z_installer.exe"
set "CurrVersion="

echo [CHECK] Verifying %AppName% installation status...

:: Fast registry check for current version
for /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /v "DisplayVersion" 2^>nul ^| findstr /i "DisplayVersion"') do (
set "ver=%%b"
)

:: Also check the display name to confirm it is the right application
for /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /v "DisplayName" 2^>nul ^| findstr /i "%AppName%"') do (
set "CurrVersion=!ver!"
)

if defined CurrVersion (
if /i "!CurrVersion!"=="%ReqVersion%" (
echo [SKIP] %AppName% %ReqVersion% is already installed.
pause
exit /b 0
) else (
echo [UPDATE] %AppName% !CurrVersion! found. Required: %ReqVersion%.
)
) else (
echo [INFO] %AppName% is not installed.
)

:: Verify the installer exists
if not exist "%Installer%" (
echo [ERROR] Installer not found: %Installer%
pause
exit /b 1
)

echo [ACTION] Starting installation...
start /wait "" "%Installer%" /S

if %errorlevel% equ 0 (
echo [SUCCESS] %AppName% %ReqVersion% installed.
) else (
echo [ERROR] Installation failed with exit code: %errorlevel%
)

pause
endlocal

How to Avoid Common Errors

Wrong Way: Using "if exists" on a folder

if exist "C:\Program Files\Chrome" only tells you that the folder is there. It doesn't tell you if the program is broken, if it's the wrong version, or if it's the 32-bit instead of the 64-bit version.

Correct Way: Use Method 1 or Method 2. Querying the Registry or the Windows Installer database (via WMIC) is the only definitive way to get the version number that the software has officially declared to the operating system.

Problem: WMIC Slowness

The wmic product command is powerful but notorious for being slow, as it scans the entire MSI database and may trigger repair operations on some packages.

Solution: Query the registry directly using reg query (Method 2), which is nearly instant and covers both MSI and non-MSI applications.

Best Practices and Rules

1. Identify "Partial" Matches

If your program name changes slightly with every version (e.g., "Python 3.10" vs "Python 3.11"), use the like operator in WMIC: wmic product where "Name like '%%Python%%'" get Name, Version

2. Administrator Privileges

While querying software lists is generally allowed, some protected MSI packages may require Administrator elevation to reveal their deep version details.

3. Log the Audit

When running a fleet-wide check, log the results to a server. This gives you a clear map of which machines are "Out of Compliance." echo %COMPUTERNAME% - %AppName% - %CurrVersion% >> version_control_audit.log

Conclusions

Checking software versions via Batch script is a fundamental step for professional system hardening and maintenance. By moving from simple "Folder checks" to version-aware comparisons, you ensure that your workstations are always running the safest, most efficient tools. This proactive oversight is essential for maintaining a high standard of security and minimizing the risk of version-related bugs across your organization.