The following code works. But I don’t get any error codes from the called process
Start-Process powershell.exe -Verb runas -ArgumentList "$Command" -Wait -PassThru
The following code returns the error messages from the called process. Powershell does not seem to be running elevated rights despite $oProcessInfo.Verb = “RunAs”.
$oProcessInfo = New-Object System.Diagnostics.ProcessStartInfo $oProcessInfo.FileName = $sProcess $oProcessInfo.Verb = "RunAs" $oProcessInfo.RedirectStandardError = $true $oProcessInfo.RedirectStandardOutput = $true $oProcessInfo.UseShellExecute = $false $oProcessInfo.Arguments = $sArgs $oProcessInfo.CreateNoWindow = $true $oProcess = New-Object System.Diagnostics.Process $oProcess.StartInfo = $oProcessInfo $oProcess.Start() | Out-Null $oProcess.WaitForExit() | Out-Null $sSTDOUT = $oProcess.StandardOutput.ReadToEnd() $sSTDERR = $oProcess.StandardError.ReadToEnd() $pOutPut.Value="Commandline: $sProcess $sArgs`r`n" $pOutPut.Value+="STDOUT: " + $sSTDOUT + "`r`n" $pOutPut.Value+="STDERR: " + $sSTDERR + "`r`n"
Does anyone have an idea what I’m doing wrong or how can I solve my problem?