• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

VBScript help for uninstalling Java

gimp

[H]F Junkie
Joined
Jul 25, 2008
Messages
10,583
So we're soon'ish going to be migrating a bunch of machines to Java 7.
We found a script online to uninstall all version of Java except a specified version.
While the script works, the downside is that if Java is in use when it's run the computer will forcefully reboot.

We need to be able to kill the Java processes (java.exe, jqs.exe, etc) prior to the uninstall.

Here's the code we found, with some minor modifications in the Sub KillProc() and an additioanl call to a KillJava function which I created and will post next.
Code:
'# Galen Dobbs - 12:42 19/03/2009
'# Uninstalls all but the chosen version of Java Runtime.
'# Based on a script by 'Daz' from the Appdeploy.com message boards.
'# Based on a script by 'muaddip' from the Appdeploy.com message boards.
'# http://www.appdeploy.com/messageboards/tm.asp?m=29809

Option Explicit

Dim wshShell, fso, strLogFile, ts, strTempDir, strTempISS, strUnString, tsIn, blFound
Dim strUninstLine, CLSID, search5, search6, search7, strJRE1, strDisplayName, strDisplayVersion
Dim strPublisher, strUninstallString, strJREUninstallString, strJREDisplayName
Dim search1, search2, search3, search4, strJREUninstallStringNEW, ret, strUninstCMD
Dim tsISS, strSetupexe, qVal, strComputername, strCurrentVersion, searchCurVer

'Change this to match the version that you don't want to have it uninstall
strCurrentVersion = "Java(TM) 7 Update 15"

qVal = 0

Set wshShell = CreateObject("WScript.Shell") 
Set fso = CreateObject("Scripting.FileSystemObject") 

strComputername = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

If Not fso.FolderExists("C:\Logs") Then fso.CreateFolder("C:\Logs")
strLogFile = "C:\Logs\Java_Uninstall_" & strComputername & ".log"
Set ts = fso.OpenTextFile(strLogFile, 8, True)

ts.WriteLine String(80, "_") 
ts.WriteLine String(80, "¯") 
ts.WriteLine Now() & " - Java Runtime(s) uninstallation"
ts.WriteLine String(80, "_") & vbCrlf

'# Generate Registry extracts from 'Uninstall' keys.
PreFlight()

'# Kill Java Processes
KillProc()

'# Kill IE or Firefox instances
KillJava()

strTempDir = wshShell.ExpandEnvironmentStrings("%temp%")
strTempISS = strTempDir & "\iss" 
strUnString = " -s -a /s /f1" 
Set tsIn = fso.OpenTextFile(strTempDir & "\uninstall.tmp", 1) 

If Not fso.FolderExists(strTempISS) Then fso.CreateFolder(strTempISS) 

blFound = False

Do While Not tsIn.AtEndOfStream
   strUninstLine = tsIn.ReadLine 
   CLSID = Mid(strUninstLine, 73, 38) 
   search5 = Instr(strUninstLine, "JRE 1") 
   search6 = Instr(strUninstLine, "]") 
   If search5 > 0 AND search6 > 0 Then 
       strJRE1 = Replace(Mid(strUninstLine, search5, search6),"]","")   
   End If 

   On Error Resume Next

   strDisplayName = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\DisplayName") 
   strDisplayVersion = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\DisplayVersion") 
   strPublisher = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\Publisher") 
   strUninstallString = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\UninstallString") 

   strJREUninstallString = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strJRE1 & "\UninstallString") 
   strJREDisplayName = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strJRE1 & "\DisplayName") 

   On Error Goto 0

   'Search for presence of Java and Sun in DisplayName and Publisher 
   search1 = Instr(1, strDisplayName, "Java", 1) 
   search2 = Instr(1, strPublisher, "Sun", 1) 
   search3 = Instr(1, strDisplayName, "J2SE", 1) 
   search4 = Instr(1, strUninstallString, "setup.exe", 1)
   search7 = InStr(1, strDisplayName, "Development", 1) + InStr(1, strDisplayName, "Java DB", 1)

   'Make sure it is not the current version
   searchCurVer = InStr(1, strDisplayName, strCurrentVersion, 1)

   If searchCurVer > 0 Then
   ts.WriteLine Now() & " - Current Version: " & strDisplayName & " found, leaving it alone."

   ElseIf strJREUninstallString <> "" Then
       blFound = True
       '# JRE 1 found
       strJREUninstallStringNEW = Replace(strJREUninstallString," -f"," -s -a /s /f") 
       ts.WriteLine Now() & " - " & strJREDisplayName
       ts.WriteLine Now() & " - Uninstall String sent: " & strJREUninstallStringNEW 
       ret = wshShell.Run(strJREUninstallStringNEW , 0, True)
       ts.WriteLine Now() & " - Return: " & ret
       If ret <> 0 And ret <> 3010 Then qVal = 1

   ElseIf search7 = 0 And search1 > 0 Or search3 > 0 And search2 > 0 Then
       blFound = True
       strUninstCMD = "msiexec.exe /x " & CLSID & " /norestart /qn REBOOT=ReallySuppress"

       If search4 > 0 Then
           '# Old InstallShield setup found
           Set tsISS = fso.OpenTextFile(strTempISS & "\" & CLSID & ".iss", 2, True)
 
           'Create Response file for any Java Version 
           tsISS.WriteLine "[InstallShield Silent]" 
           tsISS.WriteLine "Version=v6.00.000" 
           tsISS.WriteLine "File=Response File" 
           tsISS.WriteLine "[File Transfer]" 
           tsISS.WriteLine "OverwrittenReadOnly=NoToAll" 
           tsISS.WriteLine "[" & CLSID & "-DlgOrder]" 
           tsISS.WriteLine "Dlg0=" & CLSID & "-SprintfBox-0" 
           tsISS.WriteLine "Count=2" 
           tsISS.WriteLine "Dlg1=" & CLSID & "-File Transfer" 
           tsISS.WriteLine "[" & CLSID & "-SprintfBox-0]" 
           tsISS.WriteLine "Result=1" 
           tsISS.WriteLine "[Application]" 
           tsISS.WriteLine "Name=Java 2 Runtime Environment, SE v1.4.0_01"
           tsISS.WriteLine "Version=1.4.0_01"
           tsISS.WriteLine "Company=JavaSoft"
           tsISS.WriteLine "Lang=0009"
           tsISS.WriteLine "[" & CLSID & "-File Transfer]"
           tsISS.WriteLine "SharedFile=YesToAll"
           tsISS.Close

           strSetupexe = Left(strUninstallString, search4 + 9) 
           strUninstCMD =  strSetupexe & strUnString & Chr(34) & strTempISS & "\" & CLSID & ".iss" & Chr(34) 
       End If

       ts.WriteLine Now() & " - " & strDisplayName & "    - Version: " & strDisplayVersion
       ts.WriteLine Now() & " - Uninstall String sent: " & strUninstCMD
       ret = wshShell.Run(strUninstCMD , 0, True) 
       ts.WriteLine Now() & " - Return: " & ret
       If ret <> 0 And ret <> 3010 Then qVal = 1
   End If 

Loop

tsIn.Close

If Not blFound Then
   ts.WriteLine Now() & " - No Old Java Runtime versions found installed."
   qVal = 99
End If

ts.WriteLine String(80, "_") 
ts.WriteLine String(80, "¯") 
ts.Close
fso.DeleteFolder(strTempISS)
fso.DeleteFile(strTempDir & "\uninstall.tmp")

WScript.Quit(qVal)

Sub PreFlight()
   '# Creates temp files containing extracts from registry 'Uninstall' keys.
   Dim wshShell, fso, sTemp
   Set wshShell = CreateObject("WScript.Shell")
   Set fso = CreateObject("Scripting.FileSystemObject")
   sTemp = wshShell.ExpandEnvironmentStrings("%temp%")
   wshShell.Run "REGEDIT /E %temp%\registry.tmp HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall", 0, True
   wshShell.Run "cmd /c type %temp%\registry.tmp | find /i ""{"" | find /i ""}]"" > %temp%\uninstall.tmp ", 0, True
   wshShell.Run "cmd /c type %temp%\registry.tmp | find /i ""JRE 1"" >> %temp%\uninstall.tmp ", 0, True
   If Not fso.FileExists(sTemp & "\uninstall.tmp") Then
       ts.WriteLine Now() & " - No input - %temp%\uninstall.tmp Reg extract not created."
       ts.WriteLine String(80, "_") 
       ts.WriteLine String(80, "¯") 
       ts.Close
       WScript.Quit(1)
   End If
End Sub

Sub KillProc()
   On Error Resume Next
   '# kills jusched.exe and jqs.exe if they are running.  These processes will cause the installer to fail.
   Dim wshShell
   Set wshShell = CreateObject("WScript.Shell")
   wshShell.Run "Taskkill /F /IM jusched.exe /T", 0, True
   wshShell.Run "net stop JavaQuickStarterService", 0, True
   wshShell.Run "Taskkill /F /IM java.exe /T", 0, True
End Sub

Function KillJava()
Code:
Function KillJava()
	On Error Resume Next
	'strComputer = "."
	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, (Debug)}\\.\root\cimv2")
	'Kill java.exe process (unless running under SYSTEM account)
	Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'java.exe' OR Name = 'jusched.exe' OR Name = 'javaw.exe' OR Name = 'iexplore.exe'", "WQL", 48)
	For Each objProcess in colProcessList
	objProcess.Terminate()
	Next
	'Kill javaw.exe process (unless running under SYSTEM account)
	'Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'javaw.exe'")
	'For Each objProcess in colProcessList
	'objProcess.Terminate()
	'Next
	'Kill iexplore.exe process (unless running under SYSTEM account)
	'Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'iexplore.exe'")
	'For Each objProcess in colProcessList
	'objProcess.Terminate()
	'Next
End Function

There's a lot of commented stuff due to a bunch of trial and error.

Where I'm currently at:
I created a script with just the Sub KillProc() and Function KillJava()
I log on to a machine with my credentials, open up IE and a Java app.
I then run the command prompt as a different administrative user, and run the script. It successfully kills the IE process and all Java processes.

We deploy our software with LANDesk, which runs the VBS in the LocalSystem account. When deployed via LANDesk, it still forcefully reboots the machine and none of the processes get killed.

Help?
 
nevermind, found a much easier way and it works as expected.

Code:
On Error Resume Next

Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run "%comspec% /C Taskkill /F /IM jusched.exe /T", 0, True
wshShell.Run "%comspec% /C net stop JavaQuickStarterService", 0, True
wshShell.Run "%comspec% /C Taskkill /F /IM java.exe /T", 0, True
wshShell.Run "%comspec% /C Taskkill /F /IM iexplore.exe /T", 0, True
wshShell.Run "%comspec% /C Taskkill /F /IM jqs.exe /T", 0, True
wshShell.Run "%comspec% /C Taskkill /F /IM jp2launcher.exe /T", 0, True
wshShell.Run "%comspec% /C Taskkill /F /IM javaw.exe /T", 0, True

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'Uninstall Java 2 Runtime Environment, J2SE Runtime Environment
Set colJava4dot3 = objWMIService.ExecQuery("Select * from Win32_Product Where Name like 'Java 2 Runtime Environment Standard Edition %'")
For Each objSoftware in colJava4dot3
objSoftware.Uninstall()
Next


'Uninstall Java 2 Runtime Environment, J2SE Runtime Environment
Set colJava4dot3 = objWMIService.ExecQuery("Select * from Win32_Product Where Name like 'J2SE Runtime Environment %'")
For Each objSoftware in colJava4dot3
objSoftware.Uninstall()
Next

'Uninstall Java 2 Runtime Environment, SE *
Set colJava4dot3 = objWMIService.ExecQuery("Select * from Win32_Product Where Name like 'Java 2 Runtime Environment, SE %'")
For Each objSoftware in colJava4dot3
objSoftware.Uninstall()
Next

'Uninstall Java(TM) 6 Update *
Set colJava6dot = objWMIService.ExecQuery("Select * from Win32_Product Where Name like 'Java(TM) 6 Update %'")
For Each objSoftware in colJava6dot
objSoftware.Uninstall()
Next
 
Back
Top