Skip to content

Commit

Permalink
Add support for running RobloxPlayerBeta as Admin
Browse files Browse the repository at this point in the history
for some reason, i'm unable to delete the appcompatflags entry programatically in the uninstall process? weird
  • Loading branch information
pizzaboxer committed Oct 26, 2024
1 parent 643a1f0 commit aab9e15
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 31 additions & 1 deletion Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions Bloxstrap/Utility/WindowsRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Bloxstrap.Utility
static class WindowsRegistry
{
private const string RobloxPlaceKey = "Roblox.Place";

public static readonly List<RegistryKey> Roots = new() { Registry.CurrentUser, Registry.LocalMachine };

public static void RegisterProtocol(string key, string name, string handler, string handlerParam = "%1")
{
Expand Down

0 comments on commit aab9e15

Please sign in to comment.