How to automate the uninstall of Java from Windows PC’s

The following script will identify all versions of Java installed on a Windows computer (it may have several different versions installed) and then proceed to silently remove them. This script can be setup as part of a group policy to run at either Windows Startup or Shutdown. By using a group policy Java can be mass uninstalled across a large number of Windows computers at once.

The script works by looking through the registry for installed Applications which include either Java(TM) or J2SE in their display name. In our environments this matches versions 5 and 6 of the Java runtime. For each installed version of Java the script silently runs the uninstall to remove Java. Each uninstall is logged to a log file in the root of c:\. The naming standard for the log files is “jrremove-{Display name of Java version}.log”.

' removej.vbs
' Script to automatically remove all versions of Java found on PC
' Author: Matt Marschall (Red Mars Consulting) mmarschall(at)
' Date:5/9/2012
Option Explicit
Const HKEY_LOCAL_MACHINE = &H80000002
Dim oReg : Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Dim oShell : Set oShell = CreateObject("WScript.Shell")
Dim sPath, aSub, sKey, dwValue, uString,rc

' Get all keys within sPath
sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, sPath, aSub

' Loop through each key
For Each sKey In aSub
    ' Find Java uninstall strings
    oReg.GetStringValue HKEY_LOCAL_MACHINE, sPath & "\" & sKey, "DisplayName", dwValue
	if Not IsNull(dwValue) then
        if InStr(dwValue,"Java(TM)")>0 or InStr(dwValue,"J2SE")>0 then
			oReg.GetStringValue HKEY_LOCAL_MACHINE, sPath & "\" & sKey, "UninstallString", uString
			uString = replace(uString,"/I","/X")
			rc = oShell.Run(uString&" /norestart /passive /quiet /l*+ ""c:\jrremove-"&dwValue&".log""",1,true)
		end if
	end if

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • Facebook
  • Twitter
  • Google Bookmarks

Leave a Reply

Your email address will not be published. Required fields are marked *