Kaseya Community

Remove all versions of Java - Need Some Help

  • I have created a script in which I will post here to remove all versions of Java that I have found on various websites.
    The problems I have having is Vista and 7 UAC

    I have the following script, which isnt finished yet


    Script Name: Remove Java
    Script Description:

    IF User Is Logged In
    Parameter 1 :
    THEN
    Close Application - (Continue on Fail)
    Parameter 1 : javaw.exe
    OS Type : 13
    Close Application - (Continue on Fail)
    Parameter 1 : javaws.exe
    OS Type : 13
    Close Application - (Continue on Fail)
    Parameter 1 : jqs.exe
    OS Type : 13
    Close Application - (Continue on Fail)
    Parameter 1 : jusched.exe
    OS Type : 13
    Close Application - (Continue on Fail)
    Parameter 1 : iexplore.exe
    OS Type : 13
    Get Variable
    Parameter 1 : 0
    Parameter 2 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin
    Parameter 3 : OriginalSetting
    OS Type : 10
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin
    Parameter 2 : 0
    Parameter 3 : REG_DWORD
    OS Type : 10
    Write File
    Parameter 1 : #vAgentConfiguration.AgentTempDir#\RemJava.bat
    Parameter 2 : VSASharedFiles\Maintenance\Java\RemJava.bat
    OS Type : 13
    Use Credential
    OS Type : 13
    Execute Shell Command
    Parameter 1 : #vAgentConfiguration.AgentTempDir#\RemJava.bat >> #vAgentConfiguration.AgentTempDir#\RemJava.log
    Parameter 2 : 0
    OS Type : 10
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin
    Parameter 2 : #OriginalSetting#
    Parameter 3 : REG_DWORD
    OS Type : 10
    Write Script Log Entry
    Parameter 1 : All versions of Java removed.
    OS Type : 13
    ELSE


    The batch file


    @echo off & cls
    Rem List all Installation subkeys from uninstall key.
    echo Searching Registry for Java Installs
    for /f %%I in ('reg query HKLM\SOFTWARE\microsoft\windows\currentversion\uninstall') do echo %%I | find "{" > nul && call :All-Installations %%I
    echo Search Complete..
    goto :EOF
    :All-Installations
    Rem Filter out all but the Sun Installations
    for /f "tokens=2*" %%T in ('reg query %1 /v Publisher 2^> nul') do echo %%U | find "Sun" > nul && call :Sun-Installations %1
    goto :EOF
    :Sun-Installations
    Rem Filter out all but the Sun-Java Installations. Note the tilda + n, which drops all the subkeys from the path
    for /f "tokens=2*" %%T in ('reg query %1 /v DisplayName 2^> nul') do echo . Uninstalling - %%U: | find "Java" && call :Sun-Java-Installs %~n1
    goto :EOF
    :Sun-Java-Installs
    Rem Run Uninstaller for the installation
    MsiExec.exe /x%1 /qb
    echo . Uninstall Complete, Resuming Search..
    goto :EOF


    The problem I have is it runs flawlessly on XP and Vista with no-UAC but it doesn't work on Vista or 7 with UAC.

    I have the batch file running, and scanning and logging with

    Searching Registry for Java Installs
    Search Complete..

    But if I run it manually after the automated batch file runs I get the following; which obviously means it is not removing all the files.

    Searching Registry for Java Installs
    . Uninstalling - Java(TM) 6 Update 17 (64-bit):
    . Uninstall Complete, Resuming Search..
    Search Complete..
    (I get a UAC popup to allow the MSI file to run)

    What am I missing here guys?

    Legacy Forum Name: Remove all versions of Java - Need Some Help,
    Legacy Posted By Username: quicktech
  • Quicktech,

    Do you know if those reg edits actually work to temporarily disable the UAC prompts in real-time (read: The UAC process polls that registry entry and doesn't need to re-spawn via logoff/reboot)?

    If it should work, this is a complete guess, but you may also need to futs with this entry too:
    EnableInstallerDetection
    http://msdn.microsoft.com/en-us/library/cc232763%28PROT.10%29.aspx

    btw, have you read this?
    Windows 7 vulnerable to 8 out of 10 viruses
    http://www.sophos.com/blogs/chetw/g/2009/11/03/windows-7-vulnerable

    Makes me wonder if the added pain of UAC is worth the price of its protection.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Zestysoft
  • The reg edits for UAC require a reboot, the Interactive services dialog does not if i recall correctly,

    please be clear which one is stopping you..

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: thirteentwenty
  • After messing around with it all day, I couldn't get it to work.
    I have now created a running script which seems to work on Windows XP and up (including 7 and Vista)

    Beta Notes:
    If Internet Explorer or programs are open that the installer requires to be closed, the interactive services dialog box pops up.
    Internet Explorer and jqs.exe are culprits in early testing, which I now have as Close Application in the early parts of the script.
    Windows 2000 support : Early testing shows this is not working on Windows 2000 machines. (I have very few, so my testing will not be exhaustive)
    The VBS Script : Is not finalized, these are the only programs I have been testing with uninstalling.


    Script Name: Remove All Versions of Java 5 & 6
    Script Description: This script executes a VB script detecting and removing all previous Java installations. Use this to clean up a machines from any of the older Java versions.
    Dependencies: RemovaJava.vbs script
    Usage: Tested on Windows XP SP3 Vista SP1 and SP2 and 7. Run at any given time. All Java dependencies and Internet Explorer are shutdown prior to installation, ensure that this wont affect the end-user.

    IF User Is Logged In
    Parameter 1 :
    THEN
    Use Credential
    OS Type : 10
    Close Application
    Parameter 1 : jucheck.exe
    OS Type : 13
    Close Application - (Continue on Fail)
    Parameter 1 : javaw.exe
    OS Type : 13
    Close Application - (Continue on Fail)
    Parameter 1 : javaws.exe
    OS Type : 13
    Close Application - (Continue on Fail)
    Parameter 1 : jqs.exe
    OS Type : 13
    Close Application - (Continue on Fail)
    Parameter 1 : jusched.exe
    OS Type : 13
    Close Application - (Continue on Fail)
    Parameter 1 : iexplore.exe
    OS Type : 13
    Get Variable
    Parameter 1 : 0
    Parameter 2 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin
    Parameter 3 : OriginalSetting
    OS Type : 10
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin
    Parameter 2 : 0
    Parameter 3 : REG_DWORD
    OS Type : 10
    Write File
    Parameter 1 : #vAgentConfiguration.AgentTempDir#\RemoveJava.vbs
    Parameter 2 : VSASharedFiles\Maintenance\Java\RemoveJava.vbs
    OS Type : 13
    Execute Shell Command
    Parameter 1 : cscript #vAgentConfiguration.AgentTempDir#\RemoveJava.vbs >> #vAgentConfiguration.AgentTempDir#\RemoveJava.log
    Parameter 2 : 0
    OS Type : 0
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin
    Parameter 2 : #OriginalSetting#
    Parameter 3 : REG_DWORD
    OS Type : 10
    Write Script Log Entry
    Parameter 1 : All versions of Java removed.
    OS Type : 13
    ELSE

    Batch File

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

    'Uninstall Java 2 Runtime Environment Standard Edition v1.3.1_13
    Set colJava1dot3 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java 2 Runtime Environment Standard Edition v1.3.1_13'")
    For Each objSoftware in colJava1dot3
    objSoftware.Uninstall()
    Next

    'Uninstall Java 2 Runtime Environment, SE v1.4.2_08
    Set colJava1dot4 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java 2 Runtime Environment, SE v1.4.2_08'")
    For Each objSoftware in colJava1dot4
    objSoftware.Uninstall()
    Next

    'Uninstall J2SE Runtime Environment 5.0 Update 2
    Set colJava5dot2 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'J2SE Runtime Environment 5.0 Update 2'")
    For Each objSoftware in colJava5dot2
    objSoftware.Uninstall()
    Next

    'Uninstall J2SE Runtime Environment 5.0 Update 6
    Set colJava5dot6 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'J2SE Runtime Environment 5.0 Update 6'")
    For Each objSoftware in colJava5dot6
    objSoftware.Uninstall()
    Next

    'Uninstall J2SE Runtime Environment 5.0 Update 10
    Set colJava5dot10 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'J2SE Runtime Environment 5.0 Update 10'")
    For Each objSoftware in colJava5dot10
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 1
    Set colJava6dot1 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 1'")
    For Each objSoftware in colJava6dot1
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 2
    Set colJava6dot2 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 2'")
    For Each objSoftware in colJava6dot2
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 3
    Set colJava6dot3 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 3'")
    For Each objSoftware in colJava6dot3
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 4
    Set colJava6dot4 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 4'")
    For Each objSoftware in colJava6dot4
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 5
    Set colJava6dot5 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 5'")
    For Each objSoftware in colJava6dot5
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 6
    Set colJava6dot6 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 6'")
    For Each objSoftware in colJava6dot6
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 7
    Set colJava6dot7 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 7'")
    For Each objSoftware in colJava6dot7
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update8
    Set colJava6dot8 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 8'")
    For Each objSoftware in colJava6dot8
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 9
    Set colJava6dot9 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 9'")
    For Each objSoftware in colJava6dot9
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 10
    Set colJava6dot10 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 10'")
    For Each objSoftware in colJava6dot10
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 11
    Set colJava6dot11 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 11'")
    For Each objSoftware in colJava6dot11
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 12
    Set colJava6dot12 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 12'")
    For Each objSoftware in colJava6dot12
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 13
    Set colJava6dot13 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 13'")
    For Each objSoftware in colJava6dot13
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 14
    Set colJava6dot14 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 14'")
    For Each objSoftware in colJava6dot14
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 15
    Set colJava6dot15 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 15'")
    For Each objSoftware in colJava6dot15
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 16
    Set colJava6dot16 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 16'")
    For Each objSoftware in colJava6dot16
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 17 (64-bit)
    Set colJava6dot1764 = objWMIService.ExecQuery _
    ("Select * from Win32_Product " _
    & "Where Name = 'Java(TM) 6 Update 17 (64-bit)'")
    For Each objSoftware in colJava6dot1764
    objSoftware.Uninstall()
    Next

    'Uninstall Java(TM) 6 Update 17
    Set colJava6dot17 = objWMIService.ExecQuery _
    ("Select * from Win32_Product Where Name = 'Java(TM) 6 Update 17'")
    For Each objSoftware in colJava6dot17
    objSoftware.Uninstall()
    Next

    'End Script


    The UAC prompt is disabled where the user has to click allow, this also works wonders for my CCleaner script which needs to run while the user is logged in.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: quicktech