-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
57 lines (51 loc) · 1.44 KB
/
App.xaml.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
using DnsSnap.Function;
using System.Security.Principal;
using System.Windows;
namespace DnsSnap
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private static Mutex _mutex = null;
protected override void OnStartup(StartupEventArgs e)
{
if (DnsSnap.Properties.Settings.Default.Admin == "OnStart")
{
Thread.Sleep(5000);
Launch.Admin();
}
if (IsAdministrator())
{
Launch.IsAdmin = true;
}
Notificon.Run();
Launch.CheckForUpdates();
//Launch.SetStartup();
Restrict();
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e)
{
Notificon.Dispose();
base.OnExit(e);
}
private static bool IsAdministrator()
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
private void Restrict()
{
const string appName = "DnsSnap";
bool createdNew;
_mutex = new Mutex(true, appName, out createdNew);
if (!createdNew)
{
Current.Shutdown();
}
}
}
}