Parzavil
Parzavil

Reputation: 388

How do you run commands with admin privileges?

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.

Upvotes: 0

Views: 290

Answers (2)

doctorlove
doctorlove

Reputation: 19252

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:[email protected] "notepad \"my file.txt\""

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

Upvotes: 1

Nav_cfc
Nav_cfc

Reputation: 164

Use sudo as a prefix before any command you run.

Upvotes: 0

Related Questions