Thursday, January 5, 2017

<< >>
> Start > My > Template

x64 x86 msi, dynamic registry key,
msiexec uninstall

This method applies to 7-Zip, Google Chrome, Classic Shell

silent-install.cmd
@echo off
set n=7-Zip
setlocal EnableDelayedExpansion
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s | find "%n%"
if not !errorlevel!==0 (
echo %n%

:x64
if not "%ProgramFiles(x86)%"=="" (
for /f "delims=" %%f in ('dir /b "%~dp07z*x64.msi"') do (
%systemroot%\system32\msiexec.exe /i "%~dp0%%f" /qn
)
)

:x86
if "%ProgramFiles(x86)%"=="" (
for /f "delims=" %%f in ('dir /b "%~dp07z*.msi" ^| find /v "x64"') do (
%systemroot%\system32\msiexec.exe /i "%~dp0%%f" /qn
)
)

) else echo %n% already exists!
endlocal

silent-uninstall.cmd
@echo off
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
set n=7-Zip
setlocal EnableDelayedExpansion
if "%ProgramFiles(x86)%"=="" goto native

:only64bit
for /f "tokens=8 delims=\" %%a in ('^
reg query "%sw%\Wow6432Node\%u%" /s ^| find "\Uninstall\"') do (
reg query "%sw%\Wow6432Node\%u%\%%a" /v DisplayName > nul 2>&1
if !errorlevel!==0 (
reg query "%sw%\Wow6432Node\%u%\%%a" /v DisplayName | find "%n%" > nul 2>&1
if !errorlevel!==0 (
echo %%a | find "{"
if !errorlevel!==0 %systemroot%\system32\msiexec.exe /X %%a /qn
)
)
)

:native
for /f "tokens=7 delims=\" %%a in ('^
reg query "%sw%\%u%" /s ^| find "\Uninstall\"') do (
reg query "%sw%\%u%\%%a" /v DisplayName > nul 2>&1
if !errorlevel!==0 (
reg query "%sw%\%u%\%%a" /v DisplayName | find "%n%" > nul 2>&1
if !errorlevel!==0 (
echo %%a | find "{"
if !errorlevel!==0 %systemroot%\system32\msiexec.exe /X %%a /qn
)
)
)

endlocal

0 comments:

Post a Comment