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

寵の児 提交于 2020-01-03 07:26:14

问题


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 ?


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/8532925/how-to-start-a-java-jar-with-administrators-privileges-on-windows-7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!