First of all, I make no guarantees. During my testing, I have come across several problematic/broken scenarios. Oracle is to blame for those, not this script. More on that below.The web page that's parsed to look for new file IDs is currently http://www.java.com/en/download/manual.jsp - and it's parsed using HTML Agility Pack. The .NET 2.0 version of the DLL is bundled with the zip file download. You can find other .NET versions on the CodePlex page if you need them.
The logic is simple, and if the current contents of the appropriate processor architecture's last ID file does not match the latest version found on that web page, an attempt will be made to download and install the latest version. By default the last ID files are populated with the text "Default", which means Java will be installed or reinstalled with the latest version found - even if it already is installed with the latest version. Subsequent runs will say it's already the latest version since it populates the last ID file for the relevant processor architecture with the latest installed ID, after a successful install, and it will not be reinstalled/updated until the file ID on java.com changes.I became aware that silent installs of Java represent a whole world of pain. If you install Java twice silently with this script by changing the ID file's content (this script just calls the installer, so it applies to silent installs in general), you will find yourself with a broken Java install. Furthermore, I discovered that even uninstalling then, after a "double install", breaks. You'll get a rundll32.exe popup with this error: "''There was a problem starting C:\Program Files\Java\jre7\bin\installer.dll. The specified module could not be found''". To work around this I built a somewhat elaborate mechanism for uninstalling that automatically handles this scenario. The logic is quite crude and simple, and it just kills running rundll32.exe processes (yes, this will also kill anything else that might be running under rundll32.exe; I don't think it's too common for this to be running persistently, but beware). The broken behaviour seems to be related to this known bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6947907 .
Since this is based on HTML parsing, it's inherently fragile in nature, and therefore I made an attempt to be able to handle changes in the HTML flexibly without having to edit the code itself - by sticking some values in a configuration file.This script could be set up to run in a scheduled task (remember that it requires elevation / administrator privileges to install Java). Set the default working directory to the directory/folder the script and the rest of the files are in. You might want to use the -UninstallFirst option, and possibly tweak the configuration file, if you're actually using this for mass-deployment, because of the situations I talk about before where you end up with broken Java installs if it gets installed twice silently. What a mess Sun/Oracle turned this into.
This script now supports 32-bit Java on 64-bit Windows! Use the -Force32bit parameter.This PowerShell script requires PowerShell version 2 or later.
DownloadURL=http://www.java.com/en/download/manual.jsp 32-bit=Download Java software for Windows Offline 64-bit=Download Java software for Windows (64-bit) UserAgent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0 InstallString=/s UninstallSwitches=/qn /norestart UninstallDisplayNameWildcardString=Java* UninstallTimeout=45*The URL to parse can be changed by editing the configuration file.
|UninstallFirst||This will check if there's a new version of Java available before trying to uninstall, and only then will it uninstall before proceeding to install the presumed new version that's available. Possibly suited for daily runs as a scheduled task or similar (untested in the real world).|
|UninstallOnly||This will not check for new versions, and will simply uninstall all installed software found that matches the "UninstallDisplayNameWildcardString" found in the configuration file (default: "Java*"). It will not install or update Java, just uninstall.|
|NoInstall||Do not install. Sort of like a "dry run" to check for a new version.|
|Force32bit||Install a 32-bit version of Java even if the processor architecture is 64-bit (AMD64).|
Minimum cookies is the standard setting. This website uses Google Analytics and Google Ads, and these products may set cookies. By continuing to use this website, you accept this.