How do I easily elevate when running a .jar file?

When trying to run an installer Jar file, I am getting an error saying that write access is denied to create a directory under the Program Files folder.

Right click -> Run as Administrator is not available on Jar files (I assume because it is Java.exe that consumes them - they are not themselves treated as directly executable by the shell).

What is the quickest and simplest way to run a .Jar file with elevation?

I am evaluating this tool to recommend for our dev team, and they will manually install it on their boxes. I'd prefer an option that doesn't require them to type anything.


To make it easy for others to run the JAR installer without having to make changes to all their computers, you'll probably want to wrap it with a batch script that elevates and runs the JAR file. You can do this easily with the Elevation PowerToys from Microsoft. They include a useful utility that lets you launch anything as administrator by simply prefixing it with the elevate command.

Once you've downloaded them, extract them to a folder and copy the elevate.cmd and elevate.vbs to the folder with the JAR file. Then, write a new batch script with a .cmd extension with the following contents:

elevate cmd /c start "%CD%\installer.jar"

That will launch the JAR file with the default handler for such files on their system (using the start command of cmd). %CD% points to the current working directory of the script, and is necessary because the elevated command line will start in c:\windows\system32.

If, for some reason Java is not properly configured as the default handler for JAR files, that would fail though. If you can count on Java being in the same place on all systems, you could instead do it this way:

elevate "c:\Program Files\Java\jre\bin\java.exe" -jar "%CD%\installer.jar"

Once you've done either of those, just run the batch file and Windows will prompt for administrator elevation and launch the installer.

Include the elevation scripts, your script, and the installer files in a self-extracting archive that launches the script and you can wrap it up in one nice little .exe file. (7-Zip is a great open-source tool for creating such archives.)

For more information on the Elevation PowerToys, consult the linked article or the README file included with the download.


I've just had occasion to do this, and found that the easiest way, without having to download and install Elevation PowerToys, was to run cmd.exe as an administrator and then call java.exe -jar 'installer.jar' from the command line. Of course, I had to find java.exe first, but that didn't take long...