#153502 - 2005-12-15 06:03 PM
Java uninstall script
|
Scriptodude
Fresh Scripter
Registered: 2005-04-22
Posts: 26
|
Due to the recent Java RE vulnerabilities that were announced the org I work for was forced to uninstall a bunch of old Java versions. I put together the following script that reads a txt file into an array. The file is split into display names(reg uninstall key DisplayName) and uninstall strings using a semi-colon as delimeter. After reading the file into an array the script enumerates all of the unintstall keys until the DisplayName in a key matches the name in the file to the left of the semi-colon. Once it finds a match the string to the right of the semi-colon is set into a variable and then an uninstall kicked off. For the rundll32 uninstall strings we had to manually create each of the iss files and add the correct product ID/version info. The script finally kicks off an SMS hardware inventory using a vb script.
Of course this script can easily be customized to uninstall any app. Hope this helps someone out there.
Bryan
Code:
Dim $file, $u, $array Global $array Global $keys $PCNAME = @WKSTA $Jcurrent = Exist("%PROGRAMFILES%\Java\jre1.5.0_06\bin\java.exe") IF $Jcurrent <> 1 SHELL '\\servershare\jre-1_5_0_06-windows-i586-p.exe /S /v"/qn /Lev %WINDIR%\System32\WCM\SMS\J2SE_15_upd6.log"' IF @ERROR <> 0 $err = @ERROR $serr = @SERROR OPEN (1, "\\servershare\Java_15upd6_Fail.log", 5) ;write log if uninstall fails! WRITELINE (1, @DATE + " " + @TIME + " Java 2 SE 1.5 upd 6 failed to install on " + @WKSTA + " " + $err + " " + $serr + @CRLF) CLOSE(1) ELSE OPEN (1, "\\servershare\Java_15upd6_Success.log", 5) ;write log if uninstall succeeds! WRITELINE (1, @DATE + " " + @TIME + " Java 2 SE 1.5 upd 6 installed on " + @WKSTA + @CRLF) CLOSE(1) ENDIF ELSE OPEN (1, "\\servershare\Java_15upd6_Previous.log", 5) ;write log if uninstall succeeds! WRITELINE (1, @DATE + " " + @TIME + " Java 2 SE 1.5 upd 6 already installed on " + @WKSTA + @CRLF) CLOSE(1) ENDIF $key = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall" ;enumerate all of the programs shown in Add/Remove! $keys = fEnumKey($PCNAME, $key) $file = ReadFile("\\servershare\data.txt") ;read all the lines in the file into an array! For Each $f in $file ;for each line in the file $array = SPLIT($f, ";") ;split each line wherever the semi-colon is located $u = UBOUND($array) ;find my upper boundary for each line in the file! 0 will equal everything to the left of the semi-colon and 1 will equal everything to the right! For Each $k in $keys $display = readvalue($key + "\" + $k,"DisplayName") ;Read the DisplayName value for each uninstall key! IF $display = $array[0] and $display <> "" ;Do the Add/Remove display name and the name in the file match, and is displayname value not blank? $run = "%COMSPEC% /c " + $array[1] SHELL $run IF @ERROR <> 0 $err = @ERROR $serr = @SERROR OPEN (1, "\\servershare\Java_Unins_Fail.log", 5) ;write log if uninstall fails! WRITELINE (1, @DATE + " " + @TIME + " " + $array[0] + " failed to uninstall on " + @WKSTA + " " + $err + " " + $serr + @CRLF) CLOSE(1) ELSE OPEN (1, "\\servershare\Java_Unins_Success.log", 5) ;write log if uninstall succeeds! WRITELINE (1, @DATE + " " + @TIME + " " + $array[0] + " uninstalled on " + @WKSTA + @CRLF) CLOSE(1) ENDIF ENDIF Next Next
Function ReadFile($file) Dim $lf, $f, $_, $t $lf=chr(10) $f=freefilehandle $_=open($f,$file) if @error exit @error endif do $t=$t+$lf+readline($f) until @error $_=close($f) $ReadFile=split(substr($t,2),$lf) EndFunction
Function fEnumKey($PCNAME, $Key) Dim $Index, $Error, $x $Index = 0 Dim $KeyName[$Index] If $PCNAME <> "" $Key = "\\" + $PCNAME + "\" + $Key Endif
If KeyExist($Key) Do $x = ENUMKEY($Key, $Index) $Error = @Error If NOT $Error and $Index > Ubound($KeyName) ReDim PRESERVE $KeyName[$Index] Endif If NOT $Error $KeyName[$Index] = $x $Index = $Index + 1 Endif Until $Error Else $KeyName[0] = "" Exit 2 Endif $fEnumKey = $KeyName Exit 0 Endfunction
:end SHELL "%COMSPEC% /C cscript.exe \\servershare\sms-hinv.vbs" exit
Example data.txt file:
J2SE Runtime Environment 5.0 Update 3;MsiExec.exe /X{3248F0A8-6813-11D6-A77B-00B0D0150030} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_50upd3_un.log J2SE Runtime Environment 5.0 Update 2;MsiExec.exe /X{3248F0A8-6813-11D6-A77B-00B0D0150020} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_50upd2_un.log J2SE Runtime Environment 5.0 Update 1;MsiExec.exe /X{3248F0A8-6813-11D6-A77B-00B0D0150010} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_50upd1_un.log Java 2 Runtime Environment, SE v1.5.0;MsiExec.exe /X{3248F0A8-6813-11D6-A77B-00B0D0150000} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_150_un.log Java 2 Runtime Environment, SE v1.4.2_08;MsiExec.exe /X{7148F0A8-6813-11D6-A77B-00B0D0142080} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_142_08_un.log Java 2 Runtime Environment, SE v1.4.2_07;MsiExec.exe /X{7148F0A8-6813-11D6-A77B-00B0D0142070} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_142_07_un.log Java 2 Runtime Environment, SE v1.4.2_06;MsiExec.exe /X{7148F0A8-6813-11D6-A77B-00B0D0142060} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_142_06_un.log Java 2 Runtime Environment, SE v1.4.2_05;MsiExec.exe /X{7148F0A8-6813-11D6-A77B-00B0D0142050} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_142_05_un.log Java 2 Runtime Environment, SE v1.4.2_04;MsiExec.exe /X{7148F0A8-6813-11D6-A77B-00B0D0142040} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_142_04_un.log Java 2 Runtime Environment, SE v1.4.2_03;MsiExec.exe /X{7148F0A8-6813-11D6-A77B-00B0D0142030} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_142_03_un.log Java 2 Runtime Environment, SE v1.4.2_02;MsiExec.exe /X{7148F0A8-6813-11D6-A77B-00B0D0142020} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_142_02_un.log Java 2 Runtime Environment, SE v1.4.2_01;MsiExec.exe /X{7148F0A8-6813-11D6-A77B-00B0D0142010} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_142_01_un.log Java 2 Runtime Environment, SE v1.4.2;MsiExec.exe /X{7148F0A8-6813-11D6-A77B-00B0D0142000} /QN /Lev %WINDIR%\System32\WCM\SMS\J2SE_RE_142_un.log Java 2 Runtime Environment, SE v1.4.1_07;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{CA532E73-1BB7-11D8-9D6A-00010240CE95}\setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\141_07.iss -f2%WINDIR%\System32\WCM\SMS\J2141_07.log Java 2 Runtime Environment, SE v1.4.1_06;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{6E054D4D-CC57-11D7-9D67-00010240CE95}\setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\141_06.iss -f2%WINDIR%\System32\WCM\SMS\J2141_06.log Java 2 Runtime Environment, SE v1.4.1_05;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{78D082B3-ACEE-11D7-9D64-00010240CE95}\setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\141_05.iss -f2%WINDIR%\System32\WCM\SMS\J2141_05.log Java 2 Runtime Environment, SE v1.4.1_04;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{ACD27BF3-7CDC-11D7-9D4D-00010240CE95}\setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\141_04.iss -f2%WINDIR%\System32\WCM\SMS\J2141_04.log Java 2 Runtime Environment, SE v1.4.1_03;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{C4B03AEB-33D3-11D7-9D37-00010240CE95}\setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\141_03.iss -f2%WINDIR%\System32\WCM\SMS\J2141_03.log Java 2 Runtime Environment, SE v1.4.1_02;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{EFCE5837-FC21-11D6-9D24-00010240CE95}\setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\141_02.iss -f2%WINDIR%\System32\WCM\SMS\J2141_02.log Java 2 Runtime Environment, SE v1.4.1_01;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{1666FA7C-CB5F-11D6-A78C-00B0D079AF64}\setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\141_01.iss -f2%WINDIR%\System32\WCM\SMS\J2141_01.log Java 2 Runtime Environment, SE v1.4.1;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{CD0159C9-17FB-11D6-A76A-00B0D079AF64}\setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\141.iss -f2%WINDIR%\System32\WCM\SMS\J2141.log Java 2 Runtime Environment, SE v1.4.0_03;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{AC1E4C93-C1E7-11D6-9D10-00010240CE95}\Setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\140_03.iss -f2%WINDIR%\System32\WCM\SMS\J2140_03.log Java 2 Runtime Environment, SE v1.4.0_02;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{082F1B07-797C-11D6-9CFB-00010240CE95}\Setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\140_02.iss -f2%WINDIR%\System32\WCM\SMS\J2140_02.log Java 2 Runtime Environment, SE v1.4.0_01;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{7CF31609-270B-11D6-9445-000102308676}\Setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\140_01.iss -f2%WINDIR%\System32\WCM\SMS\J2140_01.log Java 2 Runtime Environment, SE v1.4.0;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{F4588301-0A06-11D6-A761-00B0D079AF64}\Setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\140.iss -f2%WINDIR%\System32\WCM\SMS\J2140.log Java 2 Runtime Environment Standard Edition v1.3.1_15;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{68249B75-B714-11D7-88E8-0050DA21757E}\Setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\131_15.iss -f2%WINDIR%\System32\WCM\SMS\J2131_15.log Java 2 Runtime Environment Standard Edition v1.3.1_14;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{68249B74-B714-11D7-88E8-0050DA21757E}\Setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\131_14.iss -f2%WINDIR%\System32\WCM\SMS\J2131_14.log Java 2 Runtime Environment Standard Edition v1.3.1_13;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{68249B73-B714-11D7-88E8-0050DA21757E}\Setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\131_13.iss -f2%WINDIR%\System32\WCM\SMS\J2131_13.log Java 2 Runtime Environment Standard Edition v1.3.1_12;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{68249B72-B714-11D7-88E8-0050DA21757E}\Setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\131_12.iss -f2%WINDIR%\System32\WCM\SMS\J2131_12.log Java 2 Runtime Environment Standard Edition v1.3.1_11;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{68249B71-B714-11D7-88E8-0050DA21757E}\Setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\131_11.iss -f2%WINDIR%\System32\WCM\SMS\J2131_11.log Java 2 Runtime Environment Standard Edition v1.3.1_10;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{68249B6E-B714-11D7-88E8-0050DA21757E}\Setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\131_10.iss -f2%WINDIR%\System32\WCM\SMS\J2131_10.log Java 2 Runtime Environment Standard Edition v1.3.1_09;RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{70F80C1E-5F26-11D7-88D1-0050DA21757E}\Setup.exe" -uninstall -s -a -s -SMS -z -f1\\servershare\131_09.iss -f2%WINDIR%\System32\WCM\SMS\J2131_09.log Java 2 Runtime Environment Standard Edition v1.3.1_06;%WINDIR%\IsUninst.EXE -F"C:\Program Files\JavaSoft\JRE\1.3.1_06\Uninst.ISU" -a -y -s Java 2 Runtime Environment Standard Edition v1.3.1_05;%WINDIR%\IsUninst.EXE -F"C:\Program Files\JavaSoft\JRE\1.3.1_05\Uninst.ISU" -a -y -s Java 2 Runtime Environment Standard Edition v1.3.1_04;%WINDIR%\IsUninst.EXE -F"C:\Program Files\JavaSoft\JRE\1.3.1_04\Uninst.ISU" -a -y -s Java 2 Runtime Environment Standard Edition v1.3.1_03;%WINDIR%\IsUninst.exe -f"C:\Program Files\JavaSoft\JRE\1.3.1_03\Uninst.isu" -a -y -s Java 2 Runtime Environment Standard Edition v1.3.1_02;%WINDIR%\IsUninst.exe -f"C:\Program Files\JavaSoft\JRE\1.3.1_02\Uninst.isu" -a -y -s Java 2 Runtime Environment Standard Edition v1.3.1_01;%WINDIR%\IsUninst.exe -f"C:\Program Files\JavaSoft\JRE\1.3.1_01\Uninst.isu" -a -y -s Java 2 Runtime Environment Standard Edition v1.3.1;%WINDIR%\IsUninst.exe -f"C:\Program Files\JavaSoft\JRE\1.3.1\Uninst.isu" -a -y -s Java 2 Runtime Environment Standard Edition v1.3.0_02;%WINDIR%\IsUninst.exe -f"C:\Program Files\JavaSoft\JRE\1.3.0_02\Uninst.isu" -a -y -s Java 2 Runtime Environment Standard Edition v1.3.0_01;%WINDIR%\IsUninst.exe -f"C:\Program Files\JavaSoft\JRE\1.3.0_01\Uninst.isu" -a -y -s Java 2 Runtime Environment Standard Edition v1.3;%WINDIR%\IsUninst.exe -f"C:\Program Files\JavaSoft\JRE\1.3\Uninst.isu" -a -y -s Java 2 Runtime Environment Standard Edition v1.2.2;%WINDIR%\IsUninst.EXE -f"C:\Program Files\JavaSoft\JRE\1.2\Uninst.isu" -a -y -s
Example iss file rundll32 string:
[InstallShield Silent] Version=v6.00.000 File=Response File [File Transfer] OverwrittenReadOnly=NoToAll [{F4588301-0A06-11D6-A761-00B0D079AF64}-DlgOrder] Dlg0={F4588301-0A06-11D6-A761-00B0D079AF64}-SprintfBox-0 Count=1 [{F4588301-0A06-11D6-A761-00B0D079AF64}-SprintfBox-0] Result=1 [Application] Name=Java 2 Runtime Environment, SE v1.4.0 Version=1.4.0 Company=JavaSoft Lang=0009
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 525 anonymous users online.
|
|
|