Skip to content

Commit

Permalink
Add admin check.
Browse files Browse the repository at this point in the history
  • Loading branch information
K4CZP3R committed Jan 16, 2021
1 parent 127d93a commit 484764d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion P2PLauncher/Utils/EnvHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -52,7 +53,11 @@ public static string Base64Decode(string base64EncodedData)
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}

public static bool IsAdministrator()
{
return (new WindowsPrincipal(WindowsIdentity.GetCurrent()))
.IsInRole(WindowsBuiltInRole.Administrator);
}
public static string GetPublicAddress()
{
try
Expand Down
7 changes: 7 additions & 0 deletions P2PLauncher/View/MainLauncherWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public partial class MainLauncherWindow : Window, IWindow
private DispatcherTimer processCheck;
private readonly string donators = "Striderstroke";


public MainLauncherWindow()
{
InitializeComponent();
Expand All @@ -47,6 +48,12 @@ public MainLauncherWindow()
dialogService);

UpdateWindow();

if(!EnvHelper.IsAdministrator())
{
MessageBox.Show("To use this application you will need administrator privileges!");
System.Environment.Exit(0);
}
}

private void SetFreeLanStatusValueLabel(string content)
Expand Down

0 comments on commit 484764d

Please # to comment.