This repository was archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (47 loc) · 1.36 KB
/
Program.cs
File metadata and controls
50 lines (47 loc) · 1.36 KB
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
using System;
using System.Diagnostics;
using System.Security.Principal;
using System.Windows.Forms;
namespace PathCleaner
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main()
{
#if !DEBUG
checkElevation();
#endif
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
#pragma warning disable CA2000 // Dispose objects before losing scope
Application.Run(new MainForm());
#pragma warning restore CA2000 // Dispose objects before losing scope
}
#if !DEBUG
private static bool isElevated()
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
private static void checkElevation()
{
if(isElevated())
{
return;
}
string selfExecutablePath = Process.GetCurrentProcess().Modules[0].FileName;
var startInfo = new ProcessStartInfo(selfExecutablePath)
{
Verb = "runas",
};
_ = Process.Start(startInfo);
Environment.Exit(0);
}
#endif
}
}