0

How do you run a command using cmd (Windows 10) in java, using admin privileges, but without opening the program with admin privileges.

For example I would want to run a command like shutdown /i, this command does not need admin privileges but others I may run will.

Parzavil
  • 388
  • 3
  • 13

2 Answers2

1

On windows, runas (run as ... ) allows you to run a program under another account. Just runas at a prompt for help. For exmaple

runas /env /user:user@domain.microsoft.com "notepad \"my file.txt\""

You need quotes and uote escaping for parameters. but basically, runas who/where then your command.

doctorlove
  • 18,872
  • 2
  • 46
  • 62
0

Use sudo as a prefix before any command you run.

Nav_cfc
  • 154
  • 1
  • 4
  • 15
  • This is for Linux or Mac OS. You could use runas for win - http://technet.microsoft.com/en-us/library/bb490994.aspx or sudowin - http://sourceforge.net/projects/sudowin/ – Nav_cfc May 10 '19 at 08:53