Wednesday, January 4, 2017

x64 x86 exe, static registry key, UninstallString without quotes,
64-bit application is hosted under 32-bit registry hive

This method applies to HandBrake

silent-instal.cmd
@echo off
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
set k=HandBrake
set n=HandBrake
if not "%ProgramFiles(x86)%"=="" set x=Wow6432Node\
setlocal EnableDelayedExpansion
reg query "%sw%\%x%%u%\%k%" > nul 2>&1
if not !errorlevel!==0 (
echo %n%

:x64
if not "%ProgramFiles(x86)%"=="" (
for /f "delims=" %%a in ('dir /b "%~dp0HandBrake-*-x86_64-Win_GUI.exe"') do (
start /wait "" "%~dp0%%a" /S
)
)

:x86
if "%ProgramFiles(x86)%"=="" (
for /f "delims=" %%a in ('dir /b "%~dp0HandBrake-*-i686-Win_GUI.exe"') do (
start /wait "" "%~dp0%%a" /S
)
)

) else echo %n% already installed
endlocal

silent-uninstall.cmd
@echo off
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
set k=HandBrake
if not "%ProgramFiles(x86)%"=="" set x=Wow6432Node\
for /f "tokens=*" %%a in ('^
reg query "%sw%\%x%%u%\%k%" /v UninstallString ^|
find "UninstallString"') do set "str=%%a"
set "first=%str:    REG_SZ    =" & set "UninstallString=%"
start /wait "" "%UninstallString%" /S

0 comments:

Post a Comment

Blog Archive