4

How would I go about running an EXE as a different user? How could I prompt for credentials or atleast ask for the password for a local admin to launch an exe through powershell. I'm having a hard time getting the runas command to work.

This was the latest thing I tried: runas -credential .\me c:\windows\system32\notepad.exe

This works in the powershell terminal: runas /user:asdf c:\windows\system32\notepad.exe but doesn't ask for credentials in a standalone powershell script.

user2746059
  • 43
  • 1
  • 1
  • 4
  • *"I'm having a hard time getting the runas command to work:* please show [as a edit to the question](http://stackoverflow.com/posts/33377545/edit) what you tried to make the runas command work – Scott Chamberlain Oct 27 '15 at 20:11
  • Possible duplicate of [Running PowerShell as another user, and launching a script](http://stackoverflow.com/questions/28989750/running-powershell-as-another-user-and-launching-a-script) – TessellatingHeckler Oct 27 '15 at 20:50
  • Please give @Nick credit and mark it answered. – Jeter-work Oct 28 '15 at 02:30
  • It works in PowerShell commandline shell, because powershell can run most executables from the commandline. `Start-Process` and `Invoke-Command` are used to run commands (PS or external) as if they were run from the commandline. – Jeter-work Oct 28 '15 at 02:33

3 Answers3

4

This is a simple operation.

Start-Process "c:\windows\system32\notepad.exe" -Credential $(Get-Credential)

Using Get-Credential will prompt the user for credentials, You can also store it in a variable.

$Creds = Get-Credential
Start-Process "c:\windows\system32\notepad.exe" -Credential $Creds
Ryan Bemrose
  • 9,018
  • 1
  • 41
  • 54
Nick
  • 1,783
  • 1
  • 15
  • 18
0

Try following

Start-Process notepad.exe -Verb RunAsUser
Jmz
  • 11
0

change directory to .exe directory and run below command

runas /netonly /user:<domain\username> .\<app name>
G T
  • 11
  • 2