-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
83 lines (70 loc) · 2.53 KB
/
Program.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
www.mbnq.pl 2024
https://mbnq.pl/
mbnq00 on gmail
*/
using System.Security.Principal;
using System.Diagnostics;
namespace redunDancer
{
internal static class Program
{
static Mutex redunDancerMutex = new Mutex(true, "{readunDancer}");
#region variables and constants
public const string mbVersion = "0.0.1.7";
#endregion
#region DPI
// not really needed, leftover from template
/*
[DllImport("user32.dll")]
static extern bool SetProcessDPIAware();
[DllImport("user32.dll")]
private static extern bool SetProcessDpiAwarenessContext(IntPtr dpiFlag);
private static readonly IntPtr DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = new IntPtr(-4);
private static readonly IntPtr DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = new IntPtr(-2);
*/
#endregion
[STAThread]
static void Main()
{
if (!redunDancerMutex.WaitOne(TimeSpan.Zero, true))
{
MessageBox.Show("Another instance of the application is already running.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Application.Exit();
return;
}
if (!IsAdministrator())
{
// Restart the application with admin rights
try
{
ProcessStartInfo proc = new ProcessStartInfo
{
UseShellExecute = true,
WorkingDirectory = Environment.CurrentDirectory,
FileName = Application.ExecutablePath,
Verb = "runas"
};
Process.Start(proc);
}
catch
{
// The user refused the elevation
MessageBox.Show("This application requires administrator privileges to run.");
}
Application.Exit();
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new mbRedunDancerMain());
redunDancerMutex.ReleaseMutex();
}
private static bool IsAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
}
}