- 1 year ago
How to reliably uninstall a Windows program with a script?
To reliably uninstall a Windows program with a script, you can use the built-in command-line utility called "msiexec." Here's an example script that you can use to uninstall a program using its product code:
batch@echo off
set PRODUCT_CODE=12345678-1234-1234-1234-1234567890AB
echo Uninstalling program...
msiexec /x %PRODUCT_CODE% /quiet
if %errorlevel% equ 0 (
echo Program successfully uninstalled.
) else (
echo Failed to uninstall the program.
)
In the script, replace 12345678-1234-1234-1234-1234567890AB
with the actual product code of the program you want to uninstall. You can usually find the product code in the program's documentation or by searching the Windows Registry.
The script uses the /x
switch with msiexec
to initiate the uninstallation process. The /quiet
switch is added to perform the uninstallation silently without displaying any user interface or prompts.
After running the msiexec
command, the script checks the %errorlevel%
to determine if the uninstallation was successful. An error level of 0
indicates success, while any other value indicates a failure.
Save the script with a .bat
extension (e.g., uninstall_program.bat
) and run it with administrator privileges by right-clicking the script and selecting "Run as administrator." This ensures that the script has the necessary permissions to uninstall the program.
Note that the effectiveness of this script depends on the program's installation method and whether it uses Windows Installer (MSI) technology. Some programs may have custom uninstallation mechanisms or require additional steps for complete removal. It's recommended to consult the program's documentation or support resources for specific uninstallation instructions if available.