Patch Management Group

 View Only
  • 1.  Looking for script to uninstall all previous versions of Java - Win7x64?

    Trusted Advisor
    Posted Jun 02, 2015 05:48 PM

    When patching Java on win7x32 via managed software policy, I used the java-uninstaller.vbs script from here without issue.  Worked great.

    I tried modifying that script to the correct locations for the registry for 64bit windows7 - replaced all the lines that were "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" and made them HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" but the script didn't work to remove Java8u31.  

    I did find a powershell script that works, but I don't love the idea of having to disable/enable signing policy to run powershell scripts.

    I tried this "Cleanup Script to Uninstall All Previous Versions of JRE" - on a machine with java 8 45 and java 8 31 - it uninstalls the 45 version instead of 31.  Judging by this post (http://wpkg.org/Java) - it seems like Oracle did something unique with 31 ("Oracle included /i in the UninstallString.") which maybe is what I'm running into with some of the scripts not being able to remove it.

    Adding /noreboot to this script works, but produces a 1605 error in the Symantec agent, I suppose when it hits an uninstall string for a version it doesn't have installed

    Anyone have any suggestions?  Someone out there in Symantec land must be scripting the uninstall of Java versions.



  • 2.  RE: Looking for script to uninstall all previous versions of Java - Win7x64?

    Posted Jun 02, 2015 06:39 PM
      |   view attached

    this is a VBS to uninstall most all versions of java runtime just run the file will give you instructions on how to use the file. I would recomend testing the command line prior to putting in a MSD policy. 

    Attachment(s)

    zip
    javauninstallscript_0.zip   4 KB 1 version


  • 3.  RE: Looking for script to uninstall all previous versions of Java - Win7x64?

    Posted Jun 03, 2015 02:34 AM

    Hi Sally,

    try this. it works for all java version. It's, like rpoltera a vbscript. copy. save it in vbs file. Then start with admin right.

     

    hope it help you.

     

    ' script to uninstall an application
    ' D clarysse
    ' date: 03 2013
    ' Version: 0.1

    ' it's look like windows update


    ' declare variable

    Option Explicit

    dim Message, Title, Icon, Choice, tmp, Instance, Application
    dim res,Shell
    Dim strComputer,oReg,UninstallKeyPath,strKeyPath,arrSubKeys,subkey,find,My_String
    Dim name,newSubkey,result,oShell,UninstallString,UninstallStringKey, Popup_String

    'declare const

    Const HKEY_LOCAL_MACHINE = &H80000002

    ' declare here the application to be uninstalled
    ' enter the application to be uninstalled
    ' it tested for java and flasplayer
    ' the thing is the this script read
    ' the uninstall string in registry
    ' so take care if there is an uninstall string
    ' with msiexec /x
    ' be carreful to take the good string
    ' because the script respects the case sensitive

    Application = "Java"


    ' Kill_Running_instance
    ' before uninstall something
    ' the script detect if there the
    ' application is  open
    ' if it opens, it kills it
    ' for java application
    ' it's kills all instance of java
    ' for another it takes the name of instance variable

    Function Kill_Running_Instance (Instance)

        Set Shell = CreateObject("WScript.Shell")
            if Instance = "Java" then
                'WScript.Echo "kill java"
                Shell.Run "taskkill /F /IM java.exe",0,true
                Shell.Run "taskkill /F /IM javaw.exe",0,true 'java without console
                Shell.Run "taskkill /F /IM jp2launcher.exe",0,true
                Shell.Run "taskkill /F /IM jqs.exe",0,true  'java quick starter
                Shell.Run "taskkill /F /IM justed.exe",0,true ' java update
            else
                'WScript.Echo "kill" & Instance
                Shell.Run  "taskkill /F /IM " & Instance,0,true
            end if
        Set Shell = Nothing
    end function


    ' Kill_All_broswer_instance kills
    ' IE, Firefox, Chrome if started

    Function Kill_All_broswer_Instance ()
        'WScript.Echo "kill all Broswer"
        Set Shell = WScript.CreateObject("WScript.Shell")
        Shell.Run "taskkill /F /IM iexplore.exe",0,true
        Shell.Run "taskkill /F /IM firefox.exe",0,true
        Shell.Run "taskkill /F /IM chrome.exe",0,true
        Set Shell = Nothing
    end function


    ' Uninstall_software uninstalls
    ' uses the uninstall string found in registry

    function Uninstall_Software(My_String)

        Set Shell = CreateObject("WScript.Shell")
        'WScript.Echo "Uninstall string soft:" & My_String
        res = Shell.Run(My_String, 1, true)
        Set Shell = Nothing
    End function


    'Find_and_kill_software
    ' try to find the application
    ' in registry
    ' then try to uninstall it
    ' with the uninstall string
    ' found in the registry
     
    Function Find_And_Kill_Software (To_Kill)

        Set oShell = CreateObject("WScript.Shell")
        strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        UninstallKeyPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
        name = "DisplayName"
        strComputer = "."
        Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
        strComputer & "\root\default:StdRegProv")
        oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
        For Each subkey In arrSubKeys
            newSubkey = UninstallKeyPath & subkey & "\" & name
         'Need to turn on error handling just in case newSubkey doesn't exist
            On Error Resume Next
            result = oShell.RegRead(newSubkey)
                    If Err.Number = 0 Then
                        find = InStr(result,To_Kill)
                        if find then 'si different de 0 donc trouve qq chose
                            UninstallStringKey = UninstallKeyPath & subkey & "\UninstallString" 'copy the uninstall string
                            UninstallString = oShell.RegRead(UninstallStringKey)
                            'WScript.echo UninstallString
                            Uninstall_Software(UninstallString & " /qn") ' add /qn to do it silencely
                        End if    
                    End If
        On Error GoTo 0
        Err.Clear
        Next
        ' end for software by default
        
        'detect if there is a 64 bites verson
        strKeyPath = "HARDWARE\DESCRIPTION\System\CentralProcessor\0"

       name = "Identifier"

    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,name,tmp

        if (instr(tmp,"64")) then
        'Perform functions for 64-bit OS
        strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
        UninstallKeyPath = "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
        name = "DisplayName"
        strComputer = "."
        Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
        strComputer & "\root\default:StdRegProv")
        oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
        For Each subkey In arrSubKeys
            newSubkey = UninstallKeyPath & subkey & "\" & name
         'Need to turn on error handling just in case newSubkey doesn't exist
            On Error Resume Next
            result = oShell.RegRead(newSubkey)
                    If Err.Number = 0 Then
                        find = InStr(result,To_Kill)
                        if find then 'si different de 0 donc trouve qq chose
                            UninstallStringKey = UninstallKeyPath & subkey & "\UninstallString" 'copy the uninstall string
                            UninstallString = oShell.RegRead(UninstallStringKey)
                            'WScript.echo UninstallString
                            Uninstall_Software(UninstallString & " /qn") ' add /qn to do it silencely
                        End if    
                    End If
        On Error GoTo 0
        Err.Clear
        Next

        'WScript.Echo "os version :" & tmp
        end if    
        
        Set oShell = Nothing

    End Function

    ' main prg
        Kill_All_broswer_Instance ()
        Kill_Running_Instance(Application)
        Find_And_Kill_Software (Application)

     

     



  • 4.  RE: Looking for script to uninstall all previous versions of Java - Win7x64?

    Trusted Advisor
    Posted Jun 03, 2015 08:17 AM

    This works if I copy it locally and run it - is there any way to have it run as a script task from the console?



  • 5.  RE: Looking for script to uninstall all previous versions of Java - Win7x64?
    Best Answer

    Posted Jun 08, 2015 05:46 AM
      |   view attached

    Attached (remove the _.txt from filename) is a script we use in our live environment.  We execute it as System so there is no dialog shown to the user.  If you execute it manually logged on as an admin you can see the msi uninstall progress.

    It logs what it did and could not do to "%TEMP%\JRE_Uninst_log.log"

    Before if attempts any uninstalls it attempts to kill jqs.exe - this is an old XP artifact as we used the same script on XP - this is not relevant on Win Vista / 7 / 8.

    Unlike the script above, my one will not force the issue - if JRE is in use it should not uninstall and the user should not be aware of the attempt.

    If any of the uninstalls return 1602, the script will exit immediately because as well as being the WI  'user cancel' return code, the Oracle JRE msi's also nicely return 1602 if a part of JRE is in use and the uninstall cannot continue.

    We use this in conjuntion will the latest JRE version install using Managed Software Delivery on Altiris 7.5, with remediation scheduled to occur at next restart.  The reason we need to use this is because JRE 8 does not upgrade previous major version JRE's (6 and 7 in our case).

    Hope this helps,

    Darren.

    Attachment(s)



  • 6.  RE: Looking for script to uninstall all previous versions of Java - Win7x64?

    Trusted Advisor
    Posted Jul 27, 2015 12:14 PM

    appreciate all of the responses.  Finally got back to testing and Darren's script appears to work well for us on both 64 & 32 bit win7.  Thanks again!