diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index ddbcc5e..b3ca337 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -138,6 +138,14 @@ namespace Bloxstrap Paths.Initialize(BaseDirectory); + // disallow running as administrator except for uninstallation + if (Utilities.IsAdministrator && !LaunchSettings.IsUninstall) + { + Frontend.ShowMessageBox("Bloxstrap does not support running in administrator mode. Relaunch or reinstall Bloxstrap with lower privileges.", MessageBoxImage.Error); + Terminate(ErrorCode.ERROR_INVALID_FUNCTION); + return; + } + // we shouldn't save settings on the first run until the first installation is finished, // just in case the user decides to cancel the install if (!IsFirstRun) diff --git a/Bloxstrap/Enums/ErrorCode.cs b/Bloxstrap/Enums/ErrorCode.cs index ba6b65e..f6b6609 100644 --- a/Bloxstrap/Enums/ErrorCode.cs +++ b/Bloxstrap/Enums/ErrorCode.cs @@ -8,6 +8,7 @@ public enum ErrorCode { ERROR_SUCCESS = 0, + ERROR_INVALID_FUNCTION = 1, ERROR_INSTALL_USEREXIT = 1602, ERROR_INSTALL_FAILURE = 1603, ERROR_CANCELLED = 1223, diff --git a/Bloxstrap/Utilities.cs b/Bloxstrap/Utilities.cs index 7f33a19..eaf3816 100644 --- a/Bloxstrap/Utilities.cs +++ b/Bloxstrap/Utilities.cs @@ -1,9 +1,18 @@ using System.ComponentModel; +using System.Security.Principal; namespace Bloxstrap { static class Utilities { + /// + /// Is process running as administrator + /// https://stackoverflow.com/a/11660205 + /// + public static bool IsAdministrator => + new WindowsPrincipal(WindowsIdentity.GetCurrent()) + .IsInRole(WindowsBuiltInRole.Administrator); + public static void ShellExecute(string website) { try