Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run command prompt as Administrator

I am developing a small shutdown scheduler project in which i have to put the computer in "Stand By" mode. The command that i am using is

Runtime.getRuntime().exec("cmd /c Powrprof.dll,SetSuspendState ");

This command requires Admin rights which i don't know how to get. Also while searching for previous answers i found i can use elevate.exe as

Runtime.getRuntime().exec("c:/elevate Rundll32.exe Powrprof.dll,SetSuspendState ");

Elevate.exe is doing the task but is consuming too much of time i.e. making the software slow. Is there any other speedy way? I am using Netbeans IDE.

like image 843
Rohan Kandwal Avatar asked Jan 30 '13 04:01

Rohan Kandwal


People also ask

How do I Run as administrator in cmd?

Using the run command To do so, open a run-box, write cmd , and press Control + Shift + Enter to open the command prompt as an administrator.

How do I open Run as administrator?

Press and hold down the SHIFT key while you right-click the executable file or the icon for the application, and then select Run as. Select The following user. In the User name and Password boxes, type the administrator account and password, and then select OK.

How do I run Command Prompt as administrator in Windows 11?

To open Windows 11 Command Prompt with Administrator privileges, you need to open the Command Prompt in a certain way. First, click the Start Menu and type cmd into the search field. Then, when the 'Command Prompt' search result is shown, right-click on it and select Run as adminsitrator, as shown below.


1 Answers

  Runtime.getRuntime().exec("runas /profile /user:Administrator \"cmd.exe /c Powrprof.dll,SetSuspendState\"");

Also plz see comments

Running as admin without Admin rights

like image 115
TheWhiteRabbit Avatar answered Sep 29 '22 16:09

TheWhiteRabbit