Geek Noise
Rants, rambles, news and notes by Peter Provost
25

Powershell Sudo (sort of) for Vista UAC -- REDUX

Sunday, 25 February 2007 13:08 by Peter Provost

Okay, after the email from Wes this morning I spent some of the time on the plane today re-doing my UAC privilege elevation stuff... this time in pure Powershell script.

As expected, it is quite simple:

function elevate {
$file = $args[0]; $param = "";
for($i=1;$i -lt $args.Length; $i++) { $param += $args[$i] + " "; }
$psi = new-object "System.Diagnostics.ProcessStartInfo"
$psi.FileName = $file; $psi.Arguments = $param; $psi.Verb = "runas";
[System.Diagnostics.Process]::Start($psi)
}

Now if only I could figure out how to have something like the Ruby "..." catch-all parameter, I could get rid of all that for-loop crap.

UPDATE 2007-02-26: I just posted a newer version of the elevate function that doesn't have the for-loop. Use that one instead.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   , ,
Categories:   Technology
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed
Comments are closed