By Rohan Kandwal

2013-01-30 04:15:57 8 Comments

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.


@Jonathan 2019-10-16 18:28:18

I'm using Windows 10. IDK why but runas isn't working and isn't reporting any errors.

I found this answer on

    powershell -Command "Start-Process 'cmd.exe /c Powrprof.dll,SetSuspendState ' -Verb runAs"
  • No password required if you have permission to elevate.
  • No shortcut required on client machine
  • No dependency on runas
  • Requires powershell

Powershell is installed by default on Windows since Windows 8 and Windows Server 2008 R2, according to an answer found on

@TheWhiteRabbit 2013-01-30 04:22:21

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

Also plz see comments

Running as admin without Admin rights

@Rohan Kandwal 2013-01-30 04:31:14

@TechExchange runas /user:Administrator cmd.exe /c Powrprof.dll,SetSuspendState will require to enter Administrator password which i donot have.

@Rohan Kandwal 2013-01-30 05:18:26

@TechExchange I don't have any passwords for my admin account and it asks for a password.

@TheWhiteRabbit 2013-01-30 05:19:55

@Deepak 2018-01-05 11:52:31

sometimes the user has to be be specified as domain\user as seen in the runas help documentation (runas /?). Using this approach or running as Administrator didn't work for me, in a corporate environment, an account may have admin rights or if it doesn't it would not be possible to get Administrator passwords. In the former case, the command still didn't run. Running in elevated access level appears to be the solution

@makarey 2014-01-13 13:14:56

Add parameter /savecred

runas /profile /user:Administrator /savecred

Input the password one times. In future OS will not ask you password.

@mikeslattery 2013-01-30 04:50:36

You have a few options

A. Create a shortcut with admin priv.

The shortcut will run cmd /c Rundll32.exe Powrprof.dll,SetSuspendState

Your Java code will run the shortcut:

Runtime rt = Runtime.getRuntime();
rt.exec("cmd /c start \"\" \"myshortcut.lnk\"")

Right click the shortcut icon > properties > advanced > run as administrator

B. Run the java process as administrator

Again, create a shortcut and set to run as administrator. Any processes spawned will also have admin privileges. Your java code will run:

rt.exec("cmd /c Powrprof.dll,SetSuspendState")

C. Use JNA to directly call SetSuspendState routine. The Java process will require admin priv (like B), but you won't have to spawn a process. If you like this, I can provide source code.

D. Use wizmo utility: wizmo quiet standby

@Rohan Kandwal 2013-01-30 05:25:49

rt.exec("cmd /c start \"\" \"myshortcut.lnk\"") but i have to make the shortcut as cmd /c Rundll32.exe Powrprof.dll,SetSuspendState but it takes a lot of time to execute the command. Is there any way by which i can increase the execution speed?

@Rohan Kandwal 2013-01-30 05:44:19

Ok one thing more if i want to use sleep option with setsuspendstatethen i have to set hibernation off. This will again require a new admin shortcut and hence two popups for acceptance. Is there a way to achieve this task in 1 shortcut or command?

@Rohan Kandwal 2013-01-30 06:23:13

Wizmo working perfectly it even has more advance options. Thanks

@owen gerig 2020-02-17 20:50:01

is there any way to get the output of the command (in my case its w32tm /query /configuration) when using a shortcut/lnk? doesnt seem like it unfortunately

Related Questions

Sponsored Content

16 Answered Questions

[SOLVED] Aliases in Windows command prompt

34 Answered Questions

[SOLVED] How do I parse command line arguments in Bash?

18 Answered Questions

[SOLVED] How do I run two commands in one line in Windows CMD?

14 Answered Questions

[SOLVED] How do I set a variable to the output of a command in Bash?

8 Answered Questions

[SOLVED] List all environment variables from the command line

18 Answered Questions

[SOLVED] How to pass command line arguments to a rake task

47 Answered Questions

[SOLVED] How do I import an SQL file using the command line in MySQL?

13 Answered Questions

[SOLVED] Run Command Prompt Commands

24 Answered Questions

[SOLVED] Is there an equivalent of 'which' on the Windows command line?

15 Answered Questions

[SOLVED] How to get a list of user accounts using the command line in MySQL?

Sponsored Content