Skip to content

Instantly share code, notes, and snippets.

@yangyer
Last active January 30, 2016 00:18

Revisions

  1. Yer Yang revised this gist Jan 30, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Start-ExecuteUAC.ps1
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ function Start-ElevatedUACSession {
    }
    $cmd = [string]::Join(" ", $args)
    Write-Host "Executing Elevated: $cmd"
    Start-Process powershell -Verb "runAs" -WindowStyle Hidden -Wait -ArgumentList "/Command ""& { $cmd > $($outputFiles.Standard) }"""
    Start-Process powershell -Verb "runAs" -WindowStyle Hidden -Wait -ArgumentList "/Command ""& { $cmd > '$($outputFiles.Standard)' }"""
    Get-Content $outputFiles.Standard
    $outputFiles.Values | Remove-Item
    }
  2. @sweeneyrobb sweeneyrobb revised this gist Jan 30, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Start-ExecuteUAC.ps1
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ function Start-ElevatedUACSession {
    }
    $cmd = [string]::Join(" ", $args)
    Write-Host "Executing Elevated: $cmd"
    Start-Process powershell -Verb "runAs" -WindowStyle Hidden -PassThru -ArgumentList "/Command ""& { $cmd > $($outputFiles.Standard) }"""
    Start-Process powershell -Verb "runAs" -WindowStyle Hidden -Wait -ArgumentList "/Command ""& { $cmd > $($outputFiles.Standard) }"""
    Get-Content $outputFiles.Standard
    $outputFiles.Values | Remove-Item
    }
  3. @sweeneyrobb sweeneyrobb revised this gist Jan 29, 2016. 1 changed file with 11 additions and 7 deletions.
    18 changes: 11 additions & 7 deletions Start-ExecuteUAC.ps1
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,12 @@
    function Start-ElevatedUACProcess {
    $splat = @{'FilePath'=$args[0];'Verb'='runAs' }
    $argList = $args[1..($args.Length)]
    if ($argList) {
    $splat.Add("ArgumentList", $argList);
    function Start-ElevatedUACSession {
    $outputFiles = @{
    Standard = [System.IO.Path]::GetTempFileName();
    Error = [System.IO.Path]::GetTempFileName();
    }
    $cmd = [string]::Join(" ", $args)
    Write-Host "Executing Elevated: $cmd"
    Start-Process powershell -Verb "runAs" -WindowStyle Hidden -PassThru -ArgumentList "/Command ""& { $cmd > $($outputFiles.Standard) }"""
    Get-Content $outputFiles.Standard
    $outputFiles.Values | Remove-Item
    }
    Start-Process @splat }
    Set-Alias sudo Start-ElevatedUACProcess
    Set-Alias sudo Start-ElevatedUACSession
  4. @sweeneyrobb sweeneyrobb revised this gist Jan 29, 2016. 1 changed file with 7 additions and 9 deletions.
    16 changes: 7 additions & 9 deletions Start-ExecuteUAC.ps1
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,8 @@
    Function Start-ElevatedUAC{
    $file, [string]$arguments = $args;
    $psi = new-object System.Diagnostics.ProcessStartInfo $file;
    $psi.Arguments = $arguments;
    $psi.Verb = "runas";
    $psi.WorkingDirectory = get-location;
    [System.Diagnostics.Process]::Start($psi);
    function Start-ElevatedUACProcess {
    $splat = @{'FilePath'=$args[0];'Verb'='runAs' }
    $argList = $args[1..($args.Length)]
    if ($argList) {
    $splat.Add("ArgumentList", $argList);
    }

    Set-Alias fudo Start-ElevatedUAC;
    Start-Process @splat }
    Set-Alias sudo Start-ElevatedUACProcess
  5. yangyer created this gist Jan 29, 2016.
    10 changes: 10 additions & 0 deletions Start-ExecuteUAC.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    Function Start-ElevatedUAC{
    $file, [string]$arguments = $args;
    $psi = new-object System.Diagnostics.ProcessStartInfo $file;
    $psi.Arguments = $arguments;
    $psi.Verb = "runas";
    $psi.WorkingDirectory = get-location;
    [System.Diagnostics.Process]::Start($psi);
    }

    Set-Alias fudo Start-ElevatedUAC;