From aab9e153d16f96ddc27a830a7ff1c892701152ad Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sat, 26 Oct 2024 23:51:40 +0100 Subject: [PATCH] Add support for running RobloxPlayerBeta as Admin for some reason, i'm unable to delete the appcompatflags entry programatically in the uninstall process? weird --- Bloxstrap/Bootstrapper.cs | 32 +++++++++++++++++++++++++++- Bloxstrap/Utility/WindowsRegistry.cs | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index a0d99630..6b73caa4 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -11,6 +11,8 @@ #warning "Automatic updater debugging is enabled" #endif +using System.ComponentModel; +using System.Data; using System.Windows; using System.Windows.Forms; using System.Windows.Shell; @@ -337,7 +339,12 @@ private void StartRoblox() WorkingDirectory = AppData.Directory }; - if (_launchMode == LaunchMode.StudioAuth) + if (_launchMode == LaunchMode.Player && ShouldRunAsAdmin()) + { + startInfo.Verb = "runas"; + startInfo.UseShellExecute = true; + } + else if (_launchMode == LaunchMode.StudioAuth) { Process.Start(startInfo); return; @@ -372,6 +379,11 @@ private void StartRoblox() using var process = Process.Start(startInfo)!; _appPid = process.Id; } + catch (Win32Exception ex) when (ex.NativeErrorCode == 1223) + { + // 1223 = ERROR_CANCELLED, gets thrown if a UAC prompt is cancelled + return; + } catch (Exception) { // attempt a reinstall on next launch @@ -456,6 +468,24 @@ private void StartRoblox() Thread.Sleep(1000); } + private bool ShouldRunAsAdmin() + { + foreach (var root in WindowsRegistry.Roots) + { + using var key = root.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"); + + if (key is null) + continue; + + string? flags = (string?)key.GetValue(AppData.ExecutablePath); + + if (flags is not null && flags.Contains("RUNASADMIN", StringComparison.OrdinalIgnoreCase)) + return true; + } + + return false; + } + public void Cancel() { const string LOG_IDENT = "Bootstrapper::Cancel"; diff --git a/Bloxstrap/Utility/WindowsRegistry.cs b/Bloxstrap/Utility/WindowsRegistry.cs index 23ca7129..c13cd65c 100644 --- a/Bloxstrap/Utility/WindowsRegistry.cs +++ b/Bloxstrap/Utility/WindowsRegistry.cs @@ -5,6 +5,8 @@ namespace Bloxstrap.Utility static class WindowsRegistry { private const string RobloxPlaceKey = "Roblox.Place"; + + public static readonly List Roots = new() { Registry.CurrentUser, Registry.LocalMachine }; public static void RegisterProtocol(string key, string name, string handler, string handlerParam = "%1") {