$ErrorActionPreference = 'Stop' $si = New-Object System.Diagnostics.ProcessStartInfo $si.FileName = $args[0] $si.Arguments = [String]::Join(' ', $args[1..($args.Count - 1)]) $si.Verb = 'RunAs' $si.UseShellExecute = $true $process = [System.Diagnostics.Process]::Start($si) # Very strange code... # But I spy it in MSBuild... # I hope these guys know what they are doing! :) $process.WaitForExit() do { [System.Threading.Thread]::Sleep(0) } while (!$process.HasExited) Exit $process.ExitCode
PS C: \ Users \ psg> Start-Process 'cmd.exe' -Verb RunAs -Wait Start-Process: Access is denied At line: 1 char: 14 + Start-Process <<<< 'cmd.exe' -Verb RunAs -Wait + CategoryInfo: NotSpecified: (:) [Start-Process], Win32Exception + FullyQualifiedErrorId: System.ComponentModel.Win32Exception, Microsoft.PowerShell.Commands.StartProcessCommand
Source: https://habr.com/ru/post/114201/
All Articles