Wednesday, January 4, 2017

only x86 msi, dynamic registry key
msiexec uninstall

This method applies to Skype, Google Drive

silent-install.cmd
@echo off
set n=Skype
if not "%ProgramFiles(x86)%"=="" set x=Wow6432Node\
setlocal EnableDelayedExpansion
reg query "HKLM\SOFTWARE\%x%Microsoft\Windows\CurrentVersion\Uninstall" /s | find "%n%"
if not !errorlevel!==0 (
for /f "tokens=*" %%a in ('dir /b "%~dp0SkypeSetup*.msi"') do (
echo %n%
%systemroot%\system32\msiexec.exe /i "%~dp0%%a" /qn
)
) else echo %n% already exists!
endlocal

silent-uninstall.cmd
@echo off
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
set n=Skype
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

Blog Archive