-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
55 lines (49 loc) · 2.01 KB
/
Copy pathProgram.cs
File metadata and controls
55 lines (49 loc) · 2.01 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
51
52
53
54
55
using System;
using System.Diagnostics;
using System.Security.Principal;
using System.Windows.Forms;
using AutoClicker.UI;
namespace AutoClicker
{
internal static class Program
{
[STAThread]
static void Main()
{
// 1. Проверяем текущие права
bool isAdmin = new WindowsPrincipal(WindowsIdentity.GetCurrent())
.IsInRole(WindowsBuiltInRole.Administrator);
// 2. Если не админ, показываем красивое окно
if (!isAdmin)
{
using var prompt = new AdminPromptForm();
DialogResult result = prompt.ShowDialog();
if (result == DialogResult.Yes)
{
// Перезапуск от имени администратора
ProcessStartInfo startInfo = new ProcessStartInfo
{
UseShellExecute = true,
WorkingDirectory = Environment.CurrentDirectory,
FileName = Environment.ProcessPath,
Verb = "runas"
};
try
{
Process.Start(startInfo);
}
catch
{
MessageBox.Show("Запуск от администратора отменён пользователем.\nПриложение будет запущено в обычном режиме.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
// Завершаем текущий процесс
return;
}
}
// 3. Запуск основного приложения
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}