Reputation: 4690
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?
Upvotes: 4
Views: 7163
Reputation: 201652
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.
Upvotes: 6