Run Java file as Administrator with full privileges

This answer is for those who are wiling to provide administrative privileges to their jars or java classes. After successfully developing an exe to edit files kept in admin. restricted directories, I have developed these steps to follow for you, hope this may help you:
Things to understand:
1) Jars won’t be directly compiled with privileges rather, you have to wrap them with some other mainfest file to finally have exe files capable of running on windows xp/ vista/ or higher version with privileges. Actually the possible answer uptil now is that before running, exe forces user to give admin rights unlike before where user is expected to know how to run jar with admin rights which isn’t friendly.

Now the simple steps:

  1. Create your jar file like try2.jar containing some mainifest file– My1.mf as like always.So, the absolute path of the jar file would be C:\try.jar.

  2. Now you need to download a software “Launch4j” which will help you to wrap jar files.Its download links is : http://sourceforge.net/projects/launch4j/files/launch4j-3/3.1.0-beta2/

  3. Now take out 5 min. and watch this tutorial: http://www.youtube.com/watch?v=mARUFRknTYQ ;this will tell you basic functions of Launch4j. But here it won’t be clear how to create a manifest file for your exe.

  4. After learning this, then create a manifest file, it is a simple text file with extension “.manifest” saved. But here certain things to be taken care of: Firstly, your mainfest file has to have same name as that of your final exe to be created. In my case, name of my exe was supposed to be “Launchme.exe” thus, my manifest file had to be named as “Launchme.manifest”. Secondly, in manifest file just copy this content:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
    <requestedPrivileges>
    <requestedExecutionLevel level="highestAvailable"   uiAccess="False" />
    </requestedPrivileges>
    </security>
    </trustInfo>
    </assembly>  
    

copy the above code into your manifest file. here line 6 is the key of whole issue. Then save it and close it.

  1. Now start Launch4j, fill all the taught textfields as like in video as per your conditions. In Wrapper mainfest column add this file manifest file. Then click “save configuration” option and then click– Build Wrapper.

Now you have exe containing your jar which requests user to give admin rights before executing. Now user is free from knowing anything other than clicks!

Leave a Comment