This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathProgram.cs
55 lines (51 loc) · 1.75 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
// Copyright (c) Microsoft Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Reflection;
using System.Security.Principal;
using System.Windows.Forms;
using CompatCheckAndMigrate.Helpers;
using Application = System.Windows.Forms.Application;
namespace CompatCheckAndMigrate
{
internal static class Program
{
[STAThread]
private static void Main()
{
if (!IsAdministrator())
{
var info = new ProcessStartInfo(Assembly.GetExecutingAssembly().GetName().Name);
info.Verb = "runas";
Process.Start(info);
Application.Exit();
}
else
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
try
{
Application.Run(new MainForm());
}
catch (Exception ex)
{
TraceHelper.Tracer.WriteTrace(ex.ToString());
MessageBox.Show(ex.ToString());
}
}
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show(((Exception) e.ExceptionObject).ToString());
}
public static bool IsAdministrator()
{
return (new WindowsPrincipal(WindowsIdentity.GetCurrent()))
.IsInRole(WindowsBuiltInRole.Administrator);
}
}
}