Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect if running elevated #1650

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/XIVLauncher/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -58,6 +59,8 @@ public class CmdLineOptions

[CommandLine.Option("clientlang", Required = false, HelpText = "Client language to use.")]
public ClientLanguage? ClientLanguage { get; set; }
[CommandLine.Option("ignore-elevated", Required = false, HelpText = "Ignore elevated check.")]
public bool IgnoreElevated { get; set; }

// We don't care about these, just need it so that the parser doesn't error
[CommandLine.Option("squirrel-updated", Hidden = true)]
Expand Down Expand Up @@ -331,6 +334,21 @@ private void App_OnStartup(object sender, StartupEventArgs e)

CommandLine = result.Value ?? new CmdLineOptions();

// Check if running elevated
if ((new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator))
{
if (CommandLine.IgnoreElevated)
{
Log.Warning("XIVLauncher is running elevated, but the user has chosen to ignore this.");
} else
{
Log.Fatal("XIVLauncher should not be run elevated. Please run normally.");
MessageBox.Show("XIVLauncher should not be run elevated. Please run normally.", "XIVLauncher", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(0);
return;
}
}

if (!string.IsNullOrEmpty(CommandLine.RoamingPath))
{
Paths.OverrideRoamingPath(CommandLine.RoamingPath);
Expand Down