Java: run as administrator Java: run as administrator windows windows

Java: run as administrator


You have to create a manifest file that specifies that your application needs administrator permissions. You can include the manifest in your exe or keep it as a separate file (yourapp.exe.manifest)

http://msdn.microsoft.com/en-us/library/bb756929.aspx


The easiest way would be to use a wrapper to launch your JVM, then elevate the wrapper. I use a simple NSIS installer script with the UAC plugin to do this:

; Java Launcher;--------------; You want to change the below lines   Name "my program"   Caption "my program Launcher"    Icon "iconfile.ico"    OutFile "java launcher.exe"; param below can be user, admin    RequestExecutionLevel admin!include UAC.nshSilentInstall silentAutoCloseWindow trueShowInstDetails showSection ""      ; command to execute      StrCpy $0 'javaw -jar myjarfile'        SetOutPath $EXEDIR      Exec $0    SectionEnd


ZippyV's answer is fine if you intend to launch the javaw.exe with system admin privileges, which if pure java code is what is getting blocked by the UAC (such as trying to write a file to a privileged directory), then that is what you will need to do.

If, however, you are trying to launch something external, but just with elevation, you could bundle an exe which elevates a command. Here is one.