views:

2036

answers:

2

Is there a way in Java to ask the system get control over the system. Without doing: Right click on an exe-> run as admin. What I want is that there comes a frame from uac like in windows vista or windows 7. Or have I to do some settings while making an exe from the jar?

+4  A: 

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

ZippyV
The problem of course is that the "executable" will be the JVM, not your own code. And since the manifest applies to the JVM, it applies to anything run by that JVM.
MSalters
What if you have a wrapper exe which launches java? Will the administrator access be inherited by the child process (jvm)?
Cal
+1  A: 

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.

Yishai