Skip to content

Instantly share code, notes, and snippets.

@mfakane
Created November 3, 2012 11:51
Show Gist options
  • Save mfakane/4007157 to your computer and use it in GitHub Desktop.
Save mfakane/4007157 to your computer and use it in GitHub Desktop.
UAC lift
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