Solved

Java Deployment

Posted on 2015-01-29
4
129 Views
Last Modified: 2015-02-27
Hi all,

I run a predepoyment task to remove old versions of Java and then deploy the new version as msi
@ECHO OFF
cls
TITLE Uninstalling Java 5-8 and Java fx. . .

wmic product where "name like 'Java 7%%'" call uninstall /nointeractive
wmic product where "name like 'Java 8%%'" call uninstall /nointeractive
wmic product where "name like 'JavaFX%%'" call uninstall /nointeractive
wmic product where "name like 'Java(TM) 7%%'" call uninstall /nointeractive
wmic product where "name like 'Java(tm) 6%%'" call uninstall /nointeractive
wmic product where "name like 'Java(TM) 8%%'" call uninstall /nointeractive
wmic product where "name like 'J2SE Runtime Environment%%'" call uninstall /nointeractive
goto END

:END
exit

Works OK, but on some PC's the computer reboots...not good when the user is engaged with work :)

Anyway to suppress reboots in wmic?
0
Comment
Question by:kwatt562
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 40578741
Hi, you cannot get the Win32_Product class to uninstall with reboot suppression, as it doesn't support any switches.  There can be issues with enumerating the Win32_Product class anyway, so I'd stay away from it.

You would be better to enumerate the registry for any installations of Java, and run their associated UninstallString commands, to which you can add /qn /norestart switches.

The following is a VBS script that you can use to do this.

Regards,

Rob.

On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002
Set objShell = CreateObject("WScript.Shell")
objShell.Run "cmd /c TASKKILL /IM Java2.exe", 0, True
arrKeys = Array("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
Set objRegistry = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\.\root\default:StdRegProv")
For Each strKey In arrKeys
	objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKey, arrSubKeys
	If Not IsNull(arrSubKeys) Then
		For Each strSubKey In arrSubKeys
			objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "DisplayName", strDisplayName
			objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "DisplayVersion", strDisplayVersion
			objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "UninstallString", strUninstallString
			If (InStr(1, strDisplayName, "Java", vbTextCompare) Or InStr(1, strDisplayName, "J2SE", vbTextCompare)) And Trim(strUninstallString) <> "" Then
				objShell.Run "cmd /c start /wait ""Java Uninstall"" " & Replace(strUninstallString, "/I", "/X") & " /qn /norestart", 0, True
			End If
			strDisplayName = vbEmpty
			strDisplayVersion = vbEmpty
			strUninstallString = vbEmpty
		Next
	End If
Next

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40578787
Oh, note that the above script only enumerates the Wow6432Node of the registry, and so only uninstalls 32 bit software.  To search for 64 bit software, remove the Wow6432Node key from that string.

Rob.
0
 
LVL 59

Expert Comment

by:LeeTutor
ID: 40635759
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question