Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a java jar with administrators privileges on windows 7

Tags:

java

windows-7

I am developing a grammar with ANTLRWorks on Windows 7. The ANTLRWorks debugger doesn't start unless ANTLRWorks has Administrator privileges. ANTLRWorks is delivered as one Java .jar which starts by a doubleclick on the file.

Question: How can I assure that the .jar file runs with Administrator Privileges ?

like image 570
nilo de roock Avatar asked Dec 16 '11 10:12

nilo de roock


People also ask

How do I run a .jar file as administrator?

Navigate to your Java installation folder, go inside the /bin/ folder, right-click on Java.exe and set it to “Run as Administrator”.

How do I give administrator permission in Java?

Run your command prompt in administrator mode. To more specific: Locate the %windir%\system32\cmd.exe file. Right click and run as administrator privilege.

How do I run a jar file in Windows 10?

Right-click your JAR file and choose Open With > Java(TM) Platform SE Binary. Tip: If you don't see that option in the “Open With” menu, then click “Choose Another App” and you'll see the option. Your JAR file will launch and you'll be able to interact with it. And that's all there is to it.


3 Answers

You can run cmd under Administrator and launch ANTRLWorks using java -jar command.

like image 56
Artem Avatar answered Oct 14 '22 05:10

Artem


You may want to have a look at Johannes Passing's Opensource Tool Elevate.exe There are many possibilities of using it. You can make a wrapper jar or simply use a batch file with something like:

Elevate.exe javaw.exe -jar path-to-your-jar-file

and this will launch UAC prompt, when allowed will permit the jar to have elevated privileges.

if you do not like batch files, then you can write a simple wrapper class to do so. Normally i make another jar file as a launcher for the jar which requires admin access, and in the launcher file, simply execute external process with the above command, and this way my jar has admin privileges.

like image 38
Johnydep Avatar answered Oct 14 '22 06:10

Johnydep


first, download this program from here http://code.kliu.org/misc/elevate/

then copy the "elevate.exe" file to the folder where your .jar file is.

Make, a .bat file as "elevate java -jar YourJARFile.jar". Run the .bat file.Simple as that.

like image 20
mavrk Avatar answered Oct 14 '22 07:10

mavrk