I am working on a java project. This project need admin privileges to execute some process in the system. For this is there any way to give admin privileges while starting the project? Is there any way to start command prompt with admin privileges from java?
Share
Disclaimer: I assume you are asking this specifically for the Windows platform
There are two ways I’d recommend:
Use the runas program
This is the easiest way and since you actually want a console window the password prompt doesn’t look awkward. On the other hand a user might find it suspicious to enter his password into a console window.
Use the CreateProcessWithLogonW API function
This requires you to use a Win32 Java library. (I’d recommend JNA). It is a little more work but it might lead to a better user experience because of the standard Windows login dialog.