Created
November 3, 2012 11:51
-
-
Save mfakane/4007157 to your computer and use it in GitHub Desktop.
UAC lift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ComponentModel; | |
using System.Diagnostics; | |
using System.Linq; | |
namespace Sudo | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (!args.Any()) | |
{ | |
Console.WriteLine("usage: sudo <command>"); | |
return; | |
} | |
var commandLine = Environment.CommandLine; | |
var selfLength = Environment.GetCommandLineArgs().First().Length + (commandLine.First() == '"' ? 2 : 0); | |
var application = args.First(); | |
var arguments = args.Length > 1 ? commandLine.Substring(selfLength + 1 + application.Length + (commandLine[selfLength + 1] == '"' ? 2 : 0) + 1) : null; | |
try | |
{ | |
Process.Start(new ProcessStartInfo(application, arguments) | |
{ | |
Verb = "runas", | |
}).Dispose(); | |
} | |
catch (Win32Exception ex) | |
{ | |
Console.Error.WriteLine("sudo: " + ex.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment