Skip to content

Commit 20f6ace

Browse files
committed
Check if elevated
before running install/uninstall from menu
1 parent 7e35f9b commit 20f6ace

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

MiningService-GUI/FormMain.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ private void stopServiceToolStripMenuItem_Click(object sender, EventArgs e)
311311

312312
private void uninstallServiceToolStripMenuItem_Click(object sender, EventArgs e)
313313
{
314+
315+
if (!Utilities.IsAdministrator())
316+
{
317+
MessageBox.Show("You must run the GUI with Admin rights to do this.");
318+
return;
319+
}
320+
314321
if (!File.Exists("MiningService.exe"))
315322
{
316323
MessageBox.Show("MiningService was not found in this directory.", "Error", MessageBoxButtons.OK);
@@ -321,6 +328,13 @@ private void uninstallServiceToolStripMenuItem_Click(object sender, EventArgs e)
321328

322329
private void installServiceToolStripMenuItem_Click(object sender, EventArgs e)
323330
{
331+
332+
if (!Utilities.IsAdministrator())
333+
{
334+
MessageBox.Show("You must run the GUI with Admin rights to do this.");
335+
return;
336+
}
337+
324338
if (!File.Exists("MiningService.exe"))
325339
{
326340
MessageBox.Show("MiningService was not found in this directory.", "Error", MessageBoxButtons.OK);

MiningService-GUI/Utilities.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Security.Principal;
45
using System.Text;
56
using System.Threading.Tasks;
67
using System.Windows.Forms;
@@ -47,5 +48,12 @@ public static DialogResult ShowInputDialog(ref string input, string title)
4748
input = textBox.Text;
4849
return result;
4950
}
51+
52+
public static bool IsAdministrator()
53+
{
54+
var identity = WindowsIdentity.GetCurrent();
55+
var principal = new WindowsPrincipal(identity);
56+
return principal.IsInRole(WindowsBuiltInRole.Administrator);
57+
}
5058
}
5159
}

0 commit comments

Comments
 (0)