Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
Awesome answer :) Thanks! I'm going to wait to accept it so maybe the question/your answer gets some more traffic (I think it works that way?) –  Merlyn Morgan-Graham Mar 26 '11 at 7:39
add comment

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...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.