From 3fb331b4596599fc4c674d4482641ee482c63589 Mon Sep 17 00:00:00 2001
From: bluepilledgreat <97983689+bluepilledgreat@users.noreply.github.com>
Date: Tue, 23 Apr 2024 16:10:06 +0100
Subject: [PATCH 1/2] disable the ability to install in admin mode
---
Bloxstrap/App.xaml.cs | 8 ++++++++
Bloxstrap/Enums/ErrorCode.cs | 1 +
Bloxstrap/Utilities.cs | 9 +++++++++
3 files changed, 18 insertions(+)
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
From 991c0574a77a2a269bfd5ed2b76889304ce3ece2 Mon Sep 17 00:00:00 2001
From: bluepilledgreat <97983689+bluepilledgreat@users.noreply.github.com>
Date: Tue, 23 Apr 2024 16:12:37 +0100
Subject: [PATCH 2/2] add in translation string
---
Bloxstrap/App.xaml.cs | 2 +-
Bloxstrap/Resources/Strings.Designer.cs | 9 +++++++++
Bloxstrap/Resources/Strings.resx | 3 +++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs
index b3ca337..70ee662 100644
--- a/Bloxstrap/App.xaml.cs
+++ b/Bloxstrap/App.xaml.cs
@@ -141,7 +141,7 @@ namespace Bloxstrap
// 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);
+ Frontend.ShowMessageBox(Bloxstrap.Resources.Strings.Bootstrapper_RanInAdminMode, MessageBoxImage.Error);
Terminate(ErrorCode.ERROR_INVALID_FUNCTION);
return;
}
diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs
index 194e71a..408db21 100644
--- a/Bloxstrap/Resources/Strings.Designer.cs
+++ b/Bloxstrap/Resources/Strings.Designer.cs
@@ -153,6 +153,15 @@ namespace Bloxstrap.Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Bloxstrap does not support running in administrator mode. Relaunch or reinstall Bloxstrap with lower privileges..
+ ///
+ public static string Bootstrapper_RanInAdminMode {
+ get {
+ return ResourceManager.GetString("Bootstrapper.RanInAdminMode", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Applying Roblox modifications....
///
diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx
index 39e5524..6e07e83 100644
--- a/Bloxstrap/Resources/Strings.resx
+++ b/Bloxstrap/Resources/Strings.resx
@@ -150,6 +150,9 @@ Your ReShade configuration files will still be saved, and you can locate them by
Bloxstrap does not have enough disk space to download and install Roblox. Please free up some disk space and try again.
+
+ Bloxstrap does not support running in administrator mode. Relaunch or reinstall Bloxstrap with lower privileges.
+
Applying Roblox modifications...