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.
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.
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.
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.
Runtime.getRuntime().exec("runas /profile /user:Administrator \"cmd.exe /c Powrprof.dll,SetSuspendState\"");
Also plz see comments
Running as admin without Admin rights
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With