How to run an application as "run as administrator" from the command prompt? [closed] How to run an application as "run as administrator" from the command prompt? [closed] powershell powershell

How to run an application as "run as administrator" from the command prompt? [closed]


Try this:

runas.exe /savecred /user:administrator "%sysdrive%\testScripts\testscript1.ps1" 

It saves the password the first time and never asks again. Maybe when you change the administrator password you will be prompted again.


See this TechNet article: Runas command documentation

From a command prompt:

C:\> runas /user:<localmachinename>\administrator cmd

Or, if you're connected to a domain:

C:\> runas /user:<DomainName>\<AdministratorAccountName> cmd


It looks like psexec -h is the way to do this:

 -h         If the target system is Windows Vista or higher, has the process            run with the account's elevated token, if available.

Which... doesn't seem to be listed in the online documentation in Sysinternals - PsExec.

But it works on my machine.