问题
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