Hello,

 I'm looking at uninstall all version of Java and then install Java 6.17. We have a program that can't run on anything higher than this. We are having problem with user getting higher version of java and we have to uninstall all version then install 6.17. I woul dlike to do this as a Script or Distribution.

 

Help

thanks

 

2 Comments   [ + ] Show Comments

Comments

  • We had one old program like that and we put the needed version of java in the same directory as the program and ran a batch file to change an environment variable to that directory prior to executing the program. That way we could keep the system version up to date and the old program ran.

    We have since put it on a Citrix VDA so we know no changes will happen to the OS or Program.
  • Could you elaborate on that please? We're facing a very similar issue and it sounds like your solution would be much more elegant than uninstalling and installing on a mass level.
Please log in to comment

Community Chosen Answer


Please log in to comment

Answers

1

I think this should take care of what you are looking to do.

Edit the BOLD areas of the script to fit your environment. 

Run the Batch script which will call the java removal script when needed. 

you will need to have all of the dependencies uploaded to the script. Those dependencies are:

jre1.6.0_17.msi

Data1.cab

javainst.vbs

javainst.bat

JRE-removal.vbs

 

what all of this does...

Silently runs javainst.bat which first checks to see if java is installed. If it is then it calls the JRE-removal.vbs this will uninstall all versions of java except the versions listed at:

aryKeepVersions = array("Java 7 Update 25 (64-Bit)","Java 7 Update 25") 

After JRE-removal.vbs has completed if the version you are have specified as 'ok' was not detected the script will notify the user that java is going to be installed and to please close their browser. The script then checks to see if the browser is open, and if it is then it pauses and notifies the user (this happens 3 times then the script exits). If the browser is closed then it silently installs the specified version of java.

 

Screenie:

 

javainst.bat

echo %DATE% %TIME% - Started>>c:\Temp\jre-windows-6u17-windows-i586_script.log

set JAVA=0

Set BROWSER=0

set COUNT=0

 

CALL :JRE_CHK

 

if %JAVA% equ 1 EXIT 

 

"C:\Program Files (x86)\Dell\KACE\KUserAlert"  -ok -name="Helpdesk" -title="Java 7 Update 17" -message="Java 6 Update 17 will be installed. Please close all browsers before continuing. This window will expire in 30 minutes and installation will automatically begin. Clicking Ok will start the installation immediately. Please contact the Helpdesk if you have any problems." -timeout="1800"

 

:BROWSER_CHECK

Set BROWSER=0

ping 127.0.0.1 -n 15

tasklist | FIND /I "iexplore.exe" && SET BROWSER=1

tasklist | FIND /I "chrome.exe" && SET BROWSER=1

tasklist | FIND /I "firefox.exe" && SET BROWSER=1

if %BROWSER% equ 1 GOTO BROWSER_OPEN

 

msiexec /i jre1.6.0_17.msi /qn AUTOUPDATECHECK=0 IEXPLORER=1 JAVAUPDATE=0 JU=0 MOZILLA=1 /L C:\Temp\jre-windows-6u17-windows-i586_script.log

 

ping 127.0.0.1 -n 15

 

echo %DATE% %TIME% - Stopped>>c:\Temp\jre-windows-6u17-windows-i586_script.log

 

CALL :JRE_CHK

if %JAVA% equ 1 GOTO JAVA_REMOVAL 

 

GOTO END

 

:BROWSER_OPEN

"C:\Program Files (x86)\Dell\KACE\KUserAlert"  -ok -name="Helpdesk" -title="Java 6 Update 17" -message="Your browser has been detected as being open. Please close your browser to complete installation." -timeout="9999"

SET /A COUNT+=1

IF %COUNT% LSS 3 (GOTO BROWSER_CHECK)

 

GOTO :EOF

 

:JAVA_REMOVAL

start /MIN cscript.exe .\JRE-removal.vbs

 

:END

"C:\Program Files (x86)\Dell\KACE\KUserAlert"  -ok -name="Helpdesk" -title="Java 6 Update 17" -message="Your version of Java 6 has been updated. Please contact the Helpdesk if you have any problems." -timeout="1800"

 

EXIT

 

:JRE_CHK

set JAVA=0

REG QUERY "HKLM\Software\WOW6432Node\JavaSoft\Java Runtime Environment" 2>nul| FIND /I "1.6.0_17" && SET JAVA=1

GOTO :EOF

 

javainst.vbs

CreateObject("Wscript.Shell").Run "javainst.bat",0,True

 

JRE-removal.vbs

'Based on a script by 'LabDeploy' from ITNinja.com message boards.

'http://www.itninja.com/question/silent-uninstall-java-all-versions

'***************************************************************************************

'-----------------------------Begin Main Script--------------------------------

OPTION EXPLICIT

 

WScript.Echo "**********************************"

WScript.Echo "Java uninstall script started at " & Now()

 

Dim objWMIService, objProcessor, objProcess

Dim colProcesses

Dim aryKeepVersions

 

'Create array of Java versions to leave installed.

'Each entry MUST match the DisplayName in the uninstall registry key for desired version.

'Since Java updates are syncronized for the most part this array works for x86 and x64.

'If you want different x86 and x64 versions, setting the array here sets it for x64 versions.

'Changing the array after the first RemoveJava call will reset it for x86 versions on a x64 system.

'Set this array to something nonsensical, like "FooBar", to remove ALL Java versions.

'aryKeepVersions = array("Java(TM) 6 Update 31","Java(TM) 6 Update 32","Java(TM) 6 Update 33","Java(TM) 6 Update 34","Java(TM) 7 Update 3","Java(TM) 7 Update 4","Java(TM) 7 Update 5","Java(TM) 7 Update 6","JavaFX 2.1.0","JavaFX 2.1.1")

aryKeepVersions = array("Java 6 Update 17 (64-Bit)","Java 6 Update 17")

 

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, (Debug)}\\.\root\cimv2")

 

'Get processor object. objProcessor.AddressWidth will give us bitness. Check objProcessor.AddressWidth = "32" or "64"

Set objProcessor = GetObject("winmgmts:\\.\root\cimv2:Win32_Processor='cpu0'")

 

'Kill processes that might prevent installs or uninstalls.

Set colProcesses = objWMIService.ExecQuery("Select Name from Win32_Process Where Name = 'jqs.exe' OR Name = 'jusched.exe' OR Name = 'jucheck.exe' OR Name = 'jp2launcher.exe' OR Name = 'java.exe' OR Name = 'javaws.exe' OR Name = 'javaw.exe'", "WQL", 48)

 

WScript.Echo vbCrLf & "----------------------------------"

WScript.Echo "Checking for problematic processes."

 

'Set this to look for errors that aren't fatal when killing processes.

On Error Resume Next

 

For Each objProcess in colProcesses
 
 

WScript.Echo "Found process " & objProcess.Name & "."

 

objProcess.Terminate()

 

Select Case Err.Number

Case 0

WScript.Echo "Killed process " & objProcess.Name & "."

Err.Clear

Case -2147217406

WScript.Echo "Process " & objProcess.Name & " already closed."

Err.Clear

Case Else

WScript.Echo "Could not kill process " & objProcess.Name & "! Aborting Script!"

WScript.Echo "Error Number: " & Err.Number

WScript.Echo "Error Description: " & Err.Description

WScript.Quit(1)

End Select

 

Next

 

'Resume normal error handling.

On Error Goto 0

 

WScript.Echo "Finished problematic process check."

WScript.Echo "----------------------------------"

 

'This call will remove x64 versions on a x64 system and x86 versions on a x86 system.

RemoveJava "Software\Microsoft\Windows\CurrentVersion\Uninstall\", aryKeepVersions, objProcessor

 

'Reset the aryKeepVersions array here to set different x86 Java versions to keep on a x64 system.

'aryKeepVersions = array("Version1", "Version2", "Version3", "Version4")

 

'This call will remove x86 versions on a x64 system.

If (objProcessor.AddressWidth = "64") Then

RemoveJava "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\", aryKeepVersions, objProcessor

End If

 

WScript.Echo vbCrLf & "Java uninstall script finished at " & Now()

WScript.Echo "**********************************"

'-------------------------------End Main Script--------------------------------

 

'---------------------------------Functions------------------------------------

Function RemoveJava(strRegistryPath, aryKeepVersions, objProcessor)

 

Dim objWSHShell, objRegistry, objWbemContext, objSWbemLocator, objSWbemServices

Dim aryUninstallKeys

Dim strUninstallKey, strDisplayName, strUninstallString, strPathToLog, strCurrentVersion

Dim intUninstallReturnCode

 

Set objWSHShell = CreateObject("WScript.Shell")

 

'Set the logfile path here. This path should already exist. String needs trailing slash.

strPathToLog = objWSHShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%") & "\Temp\"

 

'The following SWbem setup allows a script running in a x86 context, such as under the SCCM client, on a x64 system

'to access the full x64 registry. Without this the actual registry paths will be transparently redirected to the

'Wow6432Node branch for every registry call to HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall.

'Essentially this transparent redirection would hide 64bit Java runtimes from a script running in 32bit mode on a 64bit OS.

 

'Provides the bitness context parameters for registry calls. 

Set objWbemContext = CreateObject("WbemScripting.SWbemNamedValueSet")

objWbemContext.Add "__ProviderArchitecture", objProcessor.AddressWidth

objWbemContext.Add "__RequiredArchitecture", true

 

'Create SWbemLocator to connect to WMI

Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

 

'Actually connect to the WMI service using the SWbemLocator and the SWbemContext parameters.

Set objSWbemServices = objSWbemLocator.ConnectServer(".","root\default","","",,,,objWbemContext)

 

'Get the Standard Registry Provider from WMI... finally.

Set objRegistry = objSWbemServices.Get("StdRegProv")

 

'Find the Java uninstallers hiding in the uninstall key. &H80000002 = HKEY_LOCAL_MACHINE for this function call.

objRegistry.EnumKey &H80000002, strRegistryPath, aryUninstallKeys

 

'Enable VBS' poor excuse for error handling...

On Error Resume Next

 

For Each strUninstallKey In aryUninstallKeys

'These must be reset in case the GetStringValue fails to return a value. This way we don't keep values for other pieces of software.

strDisplayName = ""

strUninstallString = ""

 

'DisplayName should always be a REG_SZ

objRegistry.GetStringValue &H80000002, strRegistryPath & strUninstallKey, "DisplayName", strDisplayName

 

'Just in case GetStringValue doesn't retrieve what we want.

If Err.Number <> 0 Then

WScript.Echo "Could not retrieve DisplayName at " & strRegistryPath & strUninstallKey & "!"

WScript.Echo "Error Number: " & Err.Number

WScript.Echo "Error Description: " & Err.Description

strDisplayName = ""

Err.Clear

End If

 

'In English: If the DisplayName contains either Java OR the DisplayName contains J2SE Runtime Environment

'AND if the DisplayName does not contain Development AND if the DisplayName does not contain JavaDB

'AND if the DisplayName does not contain Web Start

'AND if the DisplayName does not contain SAS then do the if block.

'Fun, eh?

'You could remove the Web Start line to get rid of JWS but the uninstall string If block would have to account for that. It currently doesn't.

 

If ((Instr(1, strDisplayName, "Java", 1) OR (Instr(1, strDisplayName, "J2SE Runtime Environment", 1))) _

AND ((Instr(1, strDisplayName, "Development", 1) + Instr(1, strDisplayName, "JavaDB", 1)) < 1)  _

AND (Instr(1, strDisplayName, "Web Start", 1) < 1) _

AND (Instr(1, strDisplayName, "SAS", 1) < 1)) Then

 

Wscript.Echo vbCrLf & "----------------------------------"

WScript.Echo "Found version: " & strDisplayName

WScript.Echo "Found at: HKEY_LOCAL_MACHINE\" & strRegistryPath & strUninstallKey

 

'UninstallString might be a REG_EXPAND_SZ but GetStringValue should retrieve what we want.

objRegistry.GetStringValue &H80000002, strRegistryPath & strUninstallKey, "UninstallString", strUninstallString

 

'Just in case GetStringValue doesn't retrieve what we want.

If Err.Number <> 0 Then

WScript.Echo "Could not retrieve uninstall information for " & strDisplayName & "!"

WScript.Echo "Error Number: " & Err.Number

WScript.Echo "Error Description: " & Err.Description

strUninstallString = ""

Err.Clear

End If

 

'Loop through array of versions to keep and null out strUninstallString if found.

'This will cause the next If block to ignore desired versions.

For Each strCurrentVersion In aryKeepVersions

If (Instr(1, strDisplayName, strCurrentVersion, 1) > 0) Then

strUninstallString = ""

End If

Next

 

If (strUninstallString <> "") Then

'Look for very old JRE 1.1, 1.2.x, or 1.3.0 to 1.3.0_04 and 1.3.1 to 1.3.1_04 InstallShield installs.

If (Instr(1, strUninstallKey, "JRE 1", 1)) Then

strUninstallString = Replace(strUninstallString, "-f", "-a -x -y -f")

'Look for 1.3.0_05 and 1.3.1_05 to 1.3.1_20 InstallShield based installs.

ElseIf (Instr(1, strUninstallString, "-uninst", 1)) Then

strUninstallString = ""

'Look for a 1.4.0 to 1.4.1_07 InstallShield installation.

ElseIf (Instr(1, strUninstallString, "Anytext", 1)) Then

'Create ISS script for this install and fix the uninstall string.

If (CreateISSFile(strUninstallKey, objWSHShell.ExpandEnvironmentStrings("%TEMP%"))) Then

strUninstallString = Replace(strUninstallString, "Anytext", "/s /SMS /w /f1""" & objWSHShell.ExpandEnvironmentStrings("%TEMP%") & "\" _

& strUninstallKey & ".iss"" /f2""" & strPathToLog & strDisplayName & "_Uninstall.txt""")

Else

strUninstallString = ""

End If

'Look for 1.4.2 and up MSI based InstallShield installs.

ElseIf (Instr(1, strUninstallString, "msiexec.exe", 1)) Then

'Create MSIEXEC uninstall string.

strUninstallString = "MSIEXEC.EXE /X " & strUninstallKey & " /qn /norestart /l*v """ & strPathToLog & strDisplayName & "_Uninstall.txt"""

Else

strUninstallString = ""

End If

Else

strUninstallString = ""

End If

 

WScript.Echo "Uninstall string: " & strUninstallString

 

If (strUninstallString = "") Then

WScript.Echo strDisplayName & " could not be uninstalled."

Else

'Run the uninstaller.

intUninstallReturnCode = objWSHShell.Run(strUninstallString, 0, true)

WScript.Echo "Uninstall return code was: " & intUninstallReturnCode & "."

End If

 

WScript.Echo "----------------------------------"

 

End If

 

Next

 

'Resume normal quit on error behavior.

On Error GoTo 0

 

End Function

 

Function CreateISSFile(strUninstallKey, strTempPath)

On Error Resume Next

 

Dim objFileSystem, objUninstallScript

 

Set objFileSystem  = CreateObject("Scripting.FileSystemObject")

 

'Create InstallShield ISS script file for the uninstallation.

Set objUninstallScript = objFileSystem.OpenTextFile(strTempPath & "\" & strUninstallKey & ".iss", 2, True)

 

If (Err.Number <> 0) Then

WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"

WScript.Echo "Error Number: " & Err.Number

WScript.Echo "Error Description: " & Err.Description

Err.Clear

CreateISSFile = 0

End If

 

'One ugly write statement to cut down on the ammount of error checking that has to be done.

'That SharedFile=YesToAll creates problems with multiple versions of 1.4.0 to 1.4.1_07 installed.

objUninstallScript.Write "[InstallShield Silent]" & vbCrLf & "Version=v6.00.000" & vbCrLf & "File=Response File" & vbCrLf & "[File Transfer]" & _

vbCrLf & "OverwrittenReadOnly=NoToAll" & vbCrLf & "[" & strUninstallKey & "-DlgOrder]" & vbCrLf & "Dlg0=" & strUninstallKey & "-SprintfBox-0" & _

vbCrLf & "Count=2" & vbCrLf & "Dlg1=" & strUninstallKey & "-File Transfer" & vbCrLf & "[" & strUninstallKey & "-SprintfBox-0]" & vbCrLf & "Result=1" & _

vbCrLf & "[Application]" & vbCrLf & "Name=Java 2 Runtime Environment, SE v1.4.0" & vbCrLf & "Version=1.4.0" & vbCrLf & "Company=JavaSoft" & _

vbCrLf & "Lang=0009" & vbCrLf & "[" & strUninstallKey & "-File Transfer]" & vbCrLf & "SharedFile=NoToAll"

 

If (Err.Number <> 0) Then

WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"

WScript.Echo "Error Number: " & Err.Number

WScript.Echo "Error Description: " & Err.Description         

Err.Clear

CreateISSFile = 0

End If

 

objUninstallScript.Close

 

If (Err.Number <> 0) Then

WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"

WScript.Echo "Error Number: " & Err.Number

WScript.Echo "Error Description: " & Err.Description

Err.Clear

CreateISSFile = 0

End If

 

 

CreateISSFile = 1

 

End Function      
Answered 07/01/2013 by: jparkins
Blue Belt

Please log in to comment
Answer this question or Comment on this question for clarity