Skip to content

Commit 1a857de

Browse files
committed
Fix admin
1 parent 75d2bd7 commit 1a857de

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

ProcessControl/App.config

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<startup>
4-
5-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup>
65
</configuration>

ProcessControl/MainWindow.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Newtonsoft.Json.Linq;
2323
using System.Windows.Forms;
2424
using System.ComponentModel;
25+
using System.Security.Principal;
2526

2627
namespace ProcessControl
2728
{
@@ -78,6 +79,13 @@ public partial class MainWindow : Window
7879

7980
public static ObservableCollection<ProcessConfig> applyed = new ObservableCollection<ProcessConfig>();
8081

82+
public static bool IsAdministrator()
83+
{
84+
var identity = WindowsIdentity.GetCurrent();
85+
var principal = new WindowsPrincipal(identity);
86+
return principal.IsInRole(WindowsBuiltInRole.Administrator);
87+
}
88+
8189
private Task thread = null;
8290
private static Mutex mutex = new Mutex();
8391

@@ -94,6 +102,12 @@ void notifier_MouseDown(object sender, WinForms.MouseEventArgs e)
94102

95103
public MainWindow()
96104
{
105+
if (!IsAdministrator())
106+
{
107+
System.Windows.MessageBox.Show("Run application as Administrator!");
108+
throw new Exception();
109+
}
110+
97111
ShowInTaskbar = true;
98112
InitializeComponent();
99113

0 commit comments

Comments
 (0)