Skip to main content

How to Check if a Program is Installed in Batch Script

A common and critical task for any deployment or setup script is to first check for dependencies. Before your script attempts to run a program or use a utility, it should verify that the required software is actually installed on the system. This prevents errors and allows your script to provide a clear, user-friendly message if a prerequisite is missing.

This guide will teach you the most reliable and robust method for checking if a program is installed by querying the Windows Registry, which is the "source of truth" for the "Apps & features" list. You will learn how to use the REG QUERY command, how to correctly check both 32-bit and 64-bit application locations, and why other common methods should be avoided.

The Challenge: Where Does Windows Store Installation Info?

There is no single command in batch to ask, "Is Notepad++ installed?" A program's installation status is primarily recorded in the Windows Registry. The same information that populates the "Apps & features" list is stored in a specific Uninstall key in the registry. By checking this key, our script can get the most reliable answer.

The REG QUERY command is the standard tool for reading from the registry. We can use it to search the Uninstall registry keys for a program's display name.

A crucial point is that on a 64-bit Windows system, there are two Uninstall locations:

  1. For 64-bit applications: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
  2. For 32-bit applications: HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall

A robust script must check both locations.

Method 2 (For CLI Tools): Using the WHERE Command

If you are not checking for a full application but rather a command-line tool that should be in the system's PATH (like git.exe, python.exe, or curl.exe), a much simpler method is the WHERE command.

WHERE git

If git.exe is found in the PATH, this command will return its location and set %ERRORLEVEL% to 0. If not found, it returns nothing and sets %ERRORLEVEL% to 1. This is great for checking for command-line dependencies, but it doesn't check the official list of installed programs.

Method 3 (To Avoid): The Flawed wmic product Command

Many older online guides suggest using wmic product get name. This method should be avoided.

  • It is extremely slow, as it has to query the Windows Installer database.
  • It only lists software installed via MSI packages, ignoring many modern installers.
  • Most importantly, it can trigger a repair or reconfiguration of the applications it queries, which is a highly undesirable side effect.

The Script: A Full Registry Check

This script uses the recommended REG QUERY method to reliably check for an installed program. This script must be run as an Administrator.

@ECHO OFF
SETLOCAL
SET "AppName=Notepad++"
SET "IsInstalled=0"

ECHO --- Checking if "%AppName%" is installed ---
ECHO.

REM --- Check the 64-bit Uninstall key ---
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "%AppName%" | FIND /I "%AppName%" > NUL
IF %ERRORLEVEL% EQU 0 SET "IsInstalled=1"

REM --- If not found, check the 32-bit Uninstall key ---
IF %IsInstalled% EQU 0 (
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "%AppName%" | FIND /I "%AppName%" > NUL
IF %ERRORLEVEL% EQU 0 SET "IsInstalled=1"
)

ECHO --- Result ---
IF %IsInstalled% EQU 1 (
ECHO [SUCCESS] "%AppName%" is installed on this system.
) ELSE (
ECHO [FAILURE] "%AppName%" was not found.
)

ENDLOCAL

How the script works:

  • REG QUERY "KeyPath" /s /f "%AppName%": This is the core command.
    • /s: Searches all subkeys and values sub-recursively.
    • /f "%AppName%": finds data or key names that contain the string AppName.
  • | FIND /I "%AppName%": This pipe is a verification step. REG QUERY /f can sometimes have broad matches. We pipe its output to FIND to ensure a line explicitly containing our app's name is present, making the check more accurate. The /I makes it case-Insensitive.
  • > NUL: We suppress the output of FIND because we only care about its ERRORLEVEL.
  • IF %ERRORLEVEL% EQU 0 SET "IsInstalled=1": If FIND finds a match, its ERRORLEVEL is 0. We then set our flag variable to 1 (true).

Common Pitfalls and How to Solve Them

  • Administrator Rights: The HKEY_LOCAL_MACHINE (HKLM) part of the registry is a protected system area. This check will fail with "Access is denied" if the script is not run with elevated privileges. Solution: Always run the script as an Administrator.

  • Finding the Exact Name: The search string must be very close to the "Display Name" shown in "Apps & features." "Microsoft Office" is different from "Microsoft Office 365." Solution: Before scripting, check the actual name of the program in the "Apps & features" list or by manually browsing the Uninstall key in regedit.exe.

  • 32-bit vs. 64-bit: Forgetting to check the WOW6432Node path is a common mistake that will cause your script to miss any 32-bit applications installed on a 64-bit system. Solution: Always check both registry locations.

Practical Example: A Dependency Check for a 7-Zip Script

This script needs to use the 7z.exe command-line tool, so it first checks if 7-Zip is installed before attempting to create an archive.

@ECHO OFF
SETLOCAL
SET "AppName=7-Zip"
SET "IsInstalled=0"

REM --- Check both 32-bit and 64-bit locations for 7-Zip ---
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "%AppName%" | FIND /I "%AppName%" > NUL && SET "IsInstalled=1"
IF %IsInstalled% EQU 0 (
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "%AppName%" | FIND /I "%AppName%" > NUL && SET "IsInstalled=1"
)

IF %IsInstalled% EQU 0 (
ECHO [ERROR] Dependency missing: %AppName% is not installed.
ECHO Please install it before running this script.
GOTO :End
)

ECHO [SUCCESS] %AppName% is installed. Proceeding with backup...
REM Example command that uses 7-Zip
REM "C:\Program Files\7-Zip\7z.exe" a -tzip "MyBackup.zip" "C:\MyData"

:End
ENDLOCAL

Conclusion

Checking for installed programs is a fundamental part of writing robust and user-friendly deployment scripts.

  • The most reliable method is to query the Windows Registry using the REG QUERY command.
  • You must run the script as an Administrator and check both the 64-bit and 32-bit Uninstall keys for full compatibility.
  • Avoid the wmic product command, as it is slow, incomplete, and has dangerous side effects.
  • For simple command-line tools in the PATH, the WHERE command is a faster and simpler alternative.