Estimated Reading Time: 3 min
You can automate uninstallations using a batch script by leveraging Windows Management Instrumentation (WMI) or by calling the program’s own uninstaller (often available via an uninstall string stored in the registry). Below are several methods and examples:
1. Using WMIC to Uninstall a Program
WMIC (Windows Management Instrumentation Command-line) can remove programs that are installed via Windows Installer. For example:
@echo off
REM Replace "Your Program Name" with the exact name as it appears in Programs and Features.
set "programName=Your Program Name"
echo Attempting to uninstall "%programName%"...
wmic product where "name='%programName%'" call uninstall /nointeractive
echo Uninstallation command executed.
pause
Notes:
- The program must be registered in Windows Installer (it appears in WMIC’s product list).
- This command may require administrative privileges.
2. Using msiexec for MSI-Based Installers
If the program was installed with an MSI package, you can uninstall it using its Product Code (GUID). For example:
@echo off
REM Replace {PRODUCT-CODE-GUID} with the actual GUID for your application.
msiexec /x {PRODUCT-CODE-GUID} /qn
echo Uninstall command executed.
pause
Options:
/x
tells msiexec to uninstall./qn
performs the uninstallation in quiet mode (no UI). You can use/qb
for a basic UI if needed.

3. Retrieving and Using the Uninstall String from the Registry
Many applications store their uninstall command in the registry under one of these keys:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
A script can query the registry and execute the command. For example:
@echo off
setlocal enabledelayedexpansion
set "programName=Your Program Name"
set "uninstallCmd="
REM Search in HKLM uninstall registry key
for /f "tokens=2,*" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "%programName%" 2^>nul ^| find "UninstallString"') do (
set "uninstallCmd=%%B"
)
REM If not found in HKLM, try HKCU
if "!uninstallCmd!"=="" (
for /f "tokens=2,*" %%A in ('reg query "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "%programName%" 2^>nul ^| find "UninstallString"') do (
set "uninstallCmd=%%B"
)
)
if defined uninstallCmd (
echo Found uninstall command: !uninstallCmd!
REM Execute the uninstall command
call !uninstallCmd!
) else (
echo Uninstall command for "%programName%" was not found.
)
pause
Notes:
- This method requires knowing part of the program’s name as it appears in the registry.
- The uninstall string may include additional parameters (sometimes even needing to be run with quotes).
Important Considerations
- Administrative Rights: Many uninstallation operations require administrator privileges. Run your batch script “As Administrator” if needed.
- Program Variability: Not all programs are installed using MSI or register with WMIC. Some might use custom uninstallers, so verify the method for each application.
- Testing: Before deploying scripts that uninstall programs automatically, test on a non-critical machine to avoid accidental data loss or system issues.
Using these methods, you can tailor your batch script to suit the particular needs of your environment and the programs you wish to uninstall.