Last active
July 4, 2018 12:32
-
-
Save beancurd1/186a7ccd8abbe9a12f1070dd480d1601 to your computer and use it in GitHub Desktop.
This can be used to upgrade/downgrade/uninstall/deploy an application(s) via Shutdown/Startup scripts or GPO e.g. Immediate Task. Rem out the lines which useful to you.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
::This script can be used to Upgrade, Downgrade, Remove or Deploy an application | |
::It extracts software GUID, then use the GUID to search it's related keys/values pairs | |
::This is the FASTEST Way to find out Name, Version & UninstallString | |
::Get DisplayName & DisplayVersion from 32bit (or 64bit) "Java 8 Update 172" or any software Uninstall GUID, | |
::End script (or you can use this to downgrade your version of Java), if both Name and Version found and matched. | |
::If Name found but version doesn't match, get the UninstallString, uninstall ALL 32bit (or 64bit) Java then install the one defined in script silently. | |
::If Name NOT found, then end script or you can install it | |
@echo off | |
setlocal ENABLEDELAYEDEXPANSION | |
set SoftwareName=Java 8 | |
set NewVersion=8.0.1720.11 | |
set x86GUID=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | |
set x64GUID=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | |
REM set Installer=\\dc\sources\jre-8u172-windows-i586.exe | |
set Installer=D:\Downloads\Java\jre-8u172-windows-i586.exe | |
set Switch=REMOVEOUTOFDATEJRES=1 AUTO_UPDATE=0 EULA=0 NOSTARTMENU=1 SPONSORS=0 WEB_ANALYTICS=0 WEB_JAVA=1 WEB_JAVA_SECURITY_LEVEL=H /s | |
REM It's faster to first locate the software GUID, then search it's Name, Version & UninstallString | |
for /f "delims=" %%P in ('reg query "%x86GUID%" /s /f "%SoftwareName%" 2^>nul ^| findstr "HKEY_LOCAL_MACHINE"') do ( | |
echo %%P | |
reg query "%%P" /v "DisplayVersion" 2>nul | findstr /r /c:" %NewVersion%" >nul && ( | |
for /f "tokens=2*" %%A in ('reg query "%%P" /v "DisplayName" 2^>nul ^|findstr "DisplayName"') do echo %%B has already been installed | |
for /f "tokens=2*" %%A in ('reg query "%%P" /v "DisplayVersion" 2^>nul ^|findstr "DisplayVersion"') do echo Version: %%B | |
goto :EOF | |
) || ( | |
for /f "tokens=2*" %%A in ('reg query "%%P" /v "DisplayName" 2^>nul ^|findstr "DisplayName"') do echo Found other version %%B, upgrade in progress | |
for /f "tokens=2*" %%A in ('reg query "%%P" /v "UninstallString" 2^>nul ^|findstr "UninstallString"') do ( | |
echo %%B | findstr /c:"MsiExec.exe" >nul && ( | |
set UninstallStr=%%B | |
set UninstallStr=!UninstallStr:/I=/X! | |
if exist %Installer% ( | |
echo !UninstallStr! /quiet /norestart | |
rem !UninstallStr! /quiet /norestart | |
echo %Installer% %Switch% | |
rem %Installer% %Switch% | |
)else (echo %Installer% doesn't exist) | |
) || ( | |
echo None MsiExec Uninstall String %%B | |
set UninstallStr=%%B | |
rem !UninstallStr! /S | |
) | |
) | |
) | |
) | |
if not defined UninstallStr ( | |
echo %SoftwareName% not found, install it? | |
rem if exist %Installer% (%Installer% %Switch%)else (echo %Installer% doesn't exist) | |
) | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment