obso1337
asked on
Java uninstall VB Script Help
Im at my wits end. I really need a vb script that will uninstall all Java versions on workstations silently. It needs to be compatible with XP and Windows 7 x64. I use SCCM to deploy packages and I've tried a lot of things, but there are so many java versions on the enterprise it's almost impossible for me to write something that pinpoints each version. Any help would be greatly appreciated.
ASKER
I've looked at this script before. I've added the Windows 7 registry path, but it doesn't seem to uninstall. With the original echo command, it will show the correct uninstall command. It just doesn't execute. Did I put something wrong in here?
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1, ForWriting = 2
strComputer = "."
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
' Get array of subkeys under uninstall registry entry
strKeyPath = "SOFTWARE\microsoft\windows\currentversion\uninstall"
strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
CheckForJava subkey
Next
wscript.quit
sub CheckForJava(strKey)
On Error Resume Next
'DisplayName
DisplayName=WshShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strKey & "\DisplayName")
DisplayName=WshShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & strKey & "\DisplayName")
'Publisher
Publisher=WshShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strKey & "\Publisher")
Publisher=WshShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & strKey & "\Publisher")
'Search for presence of Java and Sun in DisplayName and Publisher
search1 = Instr(1, DisplayName, "Java", 1)
search2 = Instr(1, Publisher, "Sun", 1)
'Execute removal if there is a match
if search1>0 And search2>0 Then
strUninstall="MsiExec.exe /X" & strKey & " /QN"
WshShell.Run strUninstall, 1, TRUE
end if
end sub
Can you try running with elevated rights on command prompt
http://www.blogsdna.com/2168/windows-7-how-to-open-elevated-command-prompt-with-administrator-privileges.htm
http://www.blogsdna.com/2168/windows-7-how-to-open-elevated-command-prompt-with-administrator-privileges.htm
ASKER
Yeah I'll try.
ASKER
Well, I ran it from an elevated command prompt on a Windows 7 x64 system with Java 6 update 24 installed and it did nothing.
Have you tested on XP machine?
ASKER
On XP it gives me a line 13 char 1 error "Object not a collection."
When you tested in XP have you commented the modified code for win 7?
A space is missing after /X, make the necessary changes to the line
strUninstall="MsiExec.exe /X " & strKey & " /QN"
strUninstall="MsiExec.exe /X " & strKey & " /QN"
ASKER
Still doesn't work on 7 x64 and XP is giving the same error as before. I made the edit for the space after the x like you suggested.
Here is a script I wrote a long time ago - it uninstalls all versions of java going back to the original InstallShield ones. I have used it in our Enterprise of about 3000 computers.
It writes a log in C:\Logs folder, but that is configurable on lines 22 & 23.
Hope this helps,
Daz.
It writes a log in C:\Logs folder, but that is configurable on lines 22 & 23.
Hope this helps,
Daz.
'# D.Collins - 17:02 16/09/2009
'# Uninstalls any and all versions of Java Runtime.
'# Based on a script by 'muaddip' from 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
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()
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)
If 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 And ret <> 1605 And ret <> 1618 Then qVal = 1
If ret = 1618 Then qVal = 1618
ElseIf search7 = 0 And search1 > 0 Or search3 > 0 And search2 > 0 Then
blFound = True
strUninstCMD = "msiexec.exe /x " & CLSID & " /norestart /qn"
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 And ret <> 1605 And ret <> 1618 Then qVal = 1
If ret = 1618 Then qVal = 1618
End If
Loop
tsIn.Close
If Not blFound Then
ts.WriteLine Now() & " - No 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()
'# 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 "Taskkill /F /IM jqs.exe /T", 0, True
End Sub
ASKER
I've edited the script to add Win 7 functionality. The log says no java installation found though. There is java 6 update 24 installed. On XP it gave an error line 151 char 5 "unable to wait for process." Talk about crazy.
'# D.Collins - 17:02 16/09/2009
'# Uninstalls any and all versions of Java Runtime.
'# Based on a script by 'muaddip' from 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
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()
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")
strDisplayName = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\DisplayName")
strDisplayVersion = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\DisplayVersion")
strDisplayVersion = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\DisplayVersion")
strPublisher = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\Publisher")
strPublisher = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\Publisher")
strUninstallString = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\UninstallString")
strUninstallString = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\UninstallString")
strJREUninstallString = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strJRE1 & "\UninstallString")
strJREUninstallString = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & strJRE1 & "\UninstallString")
strJREDisplayName = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strJRE1 & "\DisplayName")
strJREDisplayName = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\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)
If 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 And ret <> 1605 And ret <> 1618 Then qVal = 1
If ret = 1618 Then qVal = 1618
ElseIf search7 = 0 And search1 > 0 Or search3 > 0 And search2 > 0 Then
blFound = True
strUninstCMD = "msiexec.exe /x " & CLSID & " /norestart /qn"
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 And ret <> 1605 And ret <> 1618 Then qVal = 1
If ret = 1618 Then qVal = 1618
End If
Loop
tsIn.Close
If Not blFound Then
ts.WriteLine Now() & " - No 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 "REGEDIT /E %temp%\registry.tmp HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\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()
'# 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 "Taskkill /F /IM jqs.exe /T", 0, True
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've tried your amended script, but in the logs on the 7 x64 machine I get this:
3/18/2011 10:15:06 AM - Java Runtime(s) uninstallation
__________________________ __________ __________ __________ __________ __________ ____
3/18/2011 10:15:15 AM - No Java Runtime versions found installed.
XP seems to work.
3/18/2011 10:15:06 AM - Java Runtime(s) uninstallation
__________________________
3/18/2011 10:15:15 AM - No Java Runtime versions found installed.
XP seems to work.
I'm sorry I should have said - my amended script will not work with x64.
But as I said, since JRE 6 update 11, the JRE install has been 'nice' and upgraded the previous one, without leaving old versions lying around. Bearing that in mind, there should only be one version installed on a Windows 7 computer, and installing the latest version should upgrade whatever is there.
So unless you have been installing JRE's from 2008 and earlier, I don't understand why you would need to run the script on Windows 7.
Regards,
Daz.
ASKER
Currently we are deploying java with the msi and it is not properly upgrading. So it requires us to uninstall the current version before installing the newer version. I've tried deploying the exe, but it fails the windows 7 systems.
ASKER
Wasn't exactly what I needed, but it will work.
You was a bit quick there to close this off. I have just created a script (below) that uses Windows Installer to find the Java installation and then runs an uninstall.
Please try this on Windows 7 - it is not silent and displays a pop up, but that is just for testing. If it works then I can tweak it for silent + logging.
Regards,
Daz.
Please try this on Windows 7 - it is not silent and displays a pop up, but that is just for testing. If it works then I can tweak it for silent + logging.
Regards,
Daz.
StrResults = fUninstallJRE()
MsgBox strResults
Function fUninstallJRE()
Dim wshShell, objInstaller, colProducts, oProd, strName, temp, ret, sResults
Set wshShell = CreateObject("WScript.Shell")
Set objInstaller = CreateObject("WindowsInstaller.Installer")
Set colProducts = objInstaller.Products
For Each oProd In colProducts
strName = objInstaller.ProductInfo (oProd, "ProductName")
If LCase(Left(strName, 10)) = "java(tm) 6" Then
ret = wshShell.run("msiexec /x " & oProd & " /qb", 1, True)
sResults = sResults & strName & " - Uninstall" & vbTab & "Return: " & ret & vbCrlf
End If
Next
fUninstallJRE = sResults
End Function
ASKER
That script works on both OS's. I just need it to be silent. Thanks for your hard work.
Here you go.
If you find it is not working, test it by commenting out the On Error Resume Next line to see if it gives an error.
It logs to C:\Logs\Java_Uninstall.log
Daz.
If you find it is not working, test it by commenting out the On Error Resume Next line to see if it gives an error.
It logs to C:\Logs\Java_Uninstall.log
Daz.
Option Explicit
On Error Resume Next
Dim strResults, fso, ts, strLogFile
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists("C:\Logs") Then fso.CreateFolder("C:\Logs")
strLogFile = "C:\Logs\Java_Uninstall.log"
Set ts = fso.OpenTextFile(strLogFile, 8, True)
ts.WriteLine Now() & " - Start of " & WScript.ScriptFullName
strResults = fUninstallJRE()
ts.WriteLine Now() & " - Script Complete"
Function fUninstallJRE()
Dim wshShell, objInstaller, colProducts, oProd, strName, strCmd, ret, sResults
Set wshShell = CreateObject("WScript.Shell")
Set objInstaller = CreateObject("WindowsInstaller.Installer")
Set colProducts = objInstaller.Products
For Each oProd In colProducts
strName = objInstaller.ProductInfo (oProd, "ProductName")
If LCase(Left(strName, 10)) = "java(tm) 6" Then
strCmd = "msiexec /x " & oProd & " /qn"
ts.WriteLine Now() & " - Uninstalling '" & strName & "' calling command '" & strCmd & "' ..."
ret = wshShell.run(strCmd, 0, True)
ts.WriteLine Now() & " - Return: " & ret
sResults = sResults & strName & " - Uninstall" & vbTab & "Return: " & ret & vbCrlf
End If
Next
fUninstallJRE = sResults
End Function
https://www.experts-exchange.com/questions/23508854/Need-help-with-a-VBScript-to-uninstall-all-versions-of-Java.html?sfQueryTermInfo=1+10+30+java+uninstal