01/02: The problem with Java Runtime Environment...
The problem with Java Runtime Environment is that security holes and flaws are constantly found and new patched versions and updates pop up way too often. This causes a lot of work for the person(s) in charge of keeping the Java up to date on the computers. This is especially true if the company has business critical applications that rely on JRE and if the company therefore does not allow the JRE on the workstations to update themselves automatically or if the level of permissions granted to the users is too low for using JRE's autoupdate feature.
I happen to work at such a place. As we have about 1500 computers, most of which need to have JRE installed, there's a lot of work keeping the JRE's on the workstations up to date. Even though we have a workstation management system for deploying the new Java it's a lot of work. To ease the burden of keeping the JRE environment up to date I made a simple script to remove all old versions of Java and install the new veresion.
The script checks what version(s) of Java is installed. It then removes all versions, except the most recent version. If the most recent version isn't installed it will install it. Furthermore, the script will copy the deployment.config file to the workstation. This file points the Java installation on the workstation to use settings from a central settings file. This might be useful in a corporate environment.
Please click on "Read more..." to read more :)
The script will need administrative privileges to work. Also, the location of the JRE installer file must be a trusted location (in Internet Options). Otherwise the client will get the annoying "Open file security warning" dialog box.
The script looks somewhat like this:
*----CUT HERE---*
Option Explicit
Dim msiObject, msiProduct, strProdList, strProdInfo, msiProdVersion,appName1, appName2, InstallerPath
Dim CommandShell, cmdline, strDontUninstallThis, boolNewJavaExists, fso, objShell, variable, newfolder, ConfigFile
Const msiInstallStateDefault = 5
appName1 = "java" 'Application name (or part of name) to search for and uninstall.
appName2 = "j2se" 'Name of another application to search for and uninstall (some old java versions are shown in Add/remove programs as j2se)
strDontUninstallThis = "java(tm) 6 update 18" 'Here we put the name of the version that should NOT be uninstalled.
InstallerPath = "\\Servername\sharename\jre-6u18-windows-i586-s.exe" 'Change this to reflect the path where you have saved the JRE installer file.
ConfigFile = "\\servername\sharename\deployment.config" 'Change this to reflect the path where you have saved the deployment.config file.
boolNewJavaExists = False
strProdList = ""
Set msiObject = Wscript.CreateObject("WindowsInstaller.Installer")
For Each msiProduct In msiObject.Products
If InStr(LCase(msiObject.ProductInfo(msiProduct, "ProductName")), LCase(appName1)) Then
If not (LCase(msiObject.ProductInfo(msiProduct, "ProductName")) = LCase(strDontUninstallThis)) Then
set CommandShell = createobject("wscript.shell")
cmdline = "msiexec /X " & msiProduct & " /qn"
CommandShell.run cmdline, 1, true
Else
boolNewJavaExists = True
End If
ElseIf InStr(LCase(msiObject.ProductInfo(msiProduct, "ProductName")), LCase(appName2)) Then
If not (LCase(msiObject.ProductInfo(msiProduct, "ProductName")) = LCase(strDontUninstallThis)) Then
set CommandShell = createobject("wscript.shell")
cmdline = "msiexec /X " & msiProduct & " /qn"
CommandShell.run cmdline, 1, true
Else
boolNewJavaExists = True
End If
End If
Next
If (boolNewJavaExists = False) Then
set CommandShell = createobject("wscript.shell")
cmdline = Chr(34) & InstallerPath & Chr(34) & " /s AgreeToLicense=YES IEXPLORER=1 MOZILLA=1 REBOOT=Suppress JAVAUPDATE=0"
CommandShell.run cmdline, 1, true
End If
set fso=CreateObject("Scripting.FileSystemObject")
If fso.FileExists(ConfigFile) Then
If not fso.FolderExists(EnvString("windir") & "\sun\") Then
newfolder = fso.CreateFolder(EnvString("windir") & "\sun\")
End IF
If not fso.FolderExists(EnvString("windir") & "\sun\java\") Then
newfolder = fso.CreateFolder(EnvString("windir") & "\sun\java\")
End IF
If not fso.FolderExists(EnvString("windir") & "\sun\java\deployment\") Then
newfolder = fso.CreateFolder(EnvString("windir") & "\sun\java\deployment\")
End IF
fso.CopyFile ConfigFile, EnvString("windir") & "\sun\java\deployment\"
End If
Function EnvString(variable)
'This function returns a particular environment variable’s value.
' for example, if you use EnvString("username"), it would return
' the value of %username%.
set objShell = WScript.CreateObject( "WScript.Shell" )
variable = "%" & variable & "%"
EnvString = objShell.ExpandEnvironmentStrings(variable)
Set objShell = Nothing
End Function
*----CUT HERE---*
In addition to the script you will need the JRE installer, which can be downloaded from Sun's website.
Also, you will need to create a deployment.config file, which could look somewhat like this:
*----CUT HERE---*
deployment.system.config=file:\\\\Servername\\sharename\\deployment.properties
deployment.system.config.mandatory=FALSE
*----CUT HERE---*
Finally you will need a deployment.properties file, which you should save on some server share. The file might look something like this:
*----CUT HERE---*
deployment.javaws.shortcut=NEVER
deployment.javaws.autodownload=NEVER
deployment.javaws.autodownload.locked
deployment.cache.max.size = 200
*----CUT HERE---*
You may save all files in the same network share. Just make sure it's readable from the computers. The script can be run locally on each workstation e.g. using some workstation management system. You can also run it remotely e.g. using psexec.exe.
I happen to work at such a place. As we have about 1500 computers, most of which need to have JRE installed, there's a lot of work keeping the JRE's on the workstations up to date. Even though we have a workstation management system for deploying the new Java it's a lot of work. To ease the burden of keeping the JRE environment up to date I made a simple script to remove all old versions of Java and install the new veresion.
The script checks what version(s) of Java is installed. It then removes all versions, except the most recent version. If the most recent version isn't installed it will install it. Furthermore, the script will copy the deployment.config file to the workstation. This file points the Java installation on the workstation to use settings from a central settings file. This might be useful in a corporate environment.
Please click on "Read more..." to read more :)
The script will need administrative privileges to work. Also, the location of the JRE installer file must be a trusted location (in Internet Options). Otherwise the client will get the annoying "Open file security warning" dialog box.
The script looks somewhat like this:
*----CUT HERE---*
Option Explicit
Dim msiObject, msiProduct, strProdList, strProdInfo, msiProdVersion,appName1, appName2, InstallerPath
Dim CommandShell, cmdline, strDontUninstallThis, boolNewJavaExists, fso, objShell, variable, newfolder, ConfigFile
Const msiInstallStateDefault = 5
appName1 = "java" 'Application name (or part of name) to search for and uninstall.
appName2 = "j2se" 'Name of another application to search for and uninstall (some old java versions are shown in Add/remove programs as j2se)
strDontUninstallThis = "java(tm) 6 update 18" 'Here we put the name of the version that should NOT be uninstalled.
InstallerPath = "\\Servername\sharename\jre-6u18-windows-i586-s.exe" 'Change this to reflect the path where you have saved the JRE installer file.
ConfigFile = "\\servername\sharename\deployment.config" 'Change this to reflect the path where you have saved the deployment.config file.
boolNewJavaExists = False
strProdList = ""
Set msiObject = Wscript.CreateObject("WindowsInstaller.Installer")
For Each msiProduct In msiObject.Products
If InStr(LCase(msiObject.ProductInfo(msiProduct, "ProductName")), LCase(appName1)) Then
If not (LCase(msiObject.ProductInfo(msiProduct, "ProductName")) = LCase(strDontUninstallThis)) Then
set CommandShell = createobject("wscript.shell")
cmdline = "msiexec /X " & msiProduct & " /qn"
CommandShell.run cmdline, 1, true
Else
boolNewJavaExists = True
End If
ElseIf InStr(LCase(msiObject.ProductInfo(msiProduct, "ProductName")), LCase(appName2)) Then
If not (LCase(msiObject.ProductInfo(msiProduct, "ProductName")) = LCase(strDontUninstallThis)) Then
set CommandShell = createobject("wscript.shell")
cmdline = "msiexec /X " & msiProduct & " /qn"
CommandShell.run cmdline, 1, true
Else
boolNewJavaExists = True
End If
End If
Next
If (boolNewJavaExists = False) Then
set CommandShell = createobject("wscript.shell")
cmdline = Chr(34) & InstallerPath & Chr(34) & " /s AgreeToLicense=YES IEXPLORER=1 MOZILLA=1 REBOOT=Suppress JAVAUPDATE=0"
CommandShell.run cmdline, 1, true
End If
set fso=CreateObject("Scripting.FileSystemObject")
If fso.FileExists(ConfigFile) Then
If not fso.FolderExists(EnvString("windir") & "\sun\") Then
newfolder = fso.CreateFolder(EnvString("windir") & "\sun\")
End IF
If not fso.FolderExists(EnvString("windir") & "\sun\java\") Then
newfolder = fso.CreateFolder(EnvString("windir") & "\sun\java\")
End IF
If not fso.FolderExists(EnvString("windir") & "\sun\java\deployment\") Then
newfolder = fso.CreateFolder(EnvString("windir") & "\sun\java\deployment\")
End IF
fso.CopyFile ConfigFile, EnvString("windir") & "\sun\java\deployment\"
End If
Function EnvString(variable)
'This function returns a particular environment variable’s value.
' for example, if you use EnvString("username"), it would return
' the value of %username%.
set objShell = WScript.CreateObject( "WScript.Shell" )
variable = "%" & variable & "%"
EnvString = objShell.ExpandEnvironmentStrings(variable)
Set objShell = Nothing
End Function
*----CUT HERE---*
In addition to the script you will need the JRE installer, which can be downloaded from Sun's website.
Also, you will need to create a deployment.config file, which could look somewhat like this:
*----CUT HERE---*
deployment.system.config=file:\\\\Servername\\sharename\\deployment.properties
deployment.system.config.mandatory=FALSE
*----CUT HERE---*
Finally you will need a deployment.properties file, which you should save on some server share. The file might look something like this:
*----CUT HERE---*
deployment.javaws.shortcut=NEVER
deployment.javaws.autodownload=NEVER
deployment.javaws.autodownload.locked
deployment.cache.max.size = 200
*----CUT HERE---*
You may save all files in the same network share. Just make sure it's readable from the computers. The script can be run locally on each workstation e.g. using some workstation management system. You can also run it remotely e.g. using psexec.exe.