views:

34

answers:

1

I have a c++ service application that launches a Powershell script (powershell.exe script.ps1). In the script an executable is run but needs to be run with different user credentials. Is there a way to do this in Powershell with the invoke-expression cmdlet or some other way?

+4  A: 

Try Start-Process e.g.:

Start-Process cmd.exe -arg "/k whoami.exe" -Credential (Get-Credential)

Of course, for your script you will need to create a credential programmatically rather then using the Get-Credential which prompts for username/password.

Keith Hill