mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #2173 from wabbajack-tools/no-admin
Alert when running as admin
This commit is contained in:
commit
5f56cd9c16
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Reactive.Concurrency;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
@ -36,6 +38,19 @@ namespace Wabbajack
|
||||
|
||||
private void OnStartup(object sender, StartupEventArgs e)
|
||||
{
|
||||
if (IsAdmin())
|
||||
{
|
||||
var messageBox = MessageBox.Show("Don't run Wabbajack as Admin!", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
|
||||
if (messageBox == MessageBoxResult.OK)
|
||||
{
|
||||
Environment.Exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
WebView2AutoInstaller.CheckAndInstallAsync(false, false).Wait();
|
||||
|
||||
RxApp.MainThreadScheduler = new DispatcherScheduler(Dispatcher.CurrentDispatcher);
|
||||
@ -80,6 +95,22 @@ namespace Wabbajack
|
||||
});
|
||||
}
|
||||
|
||||
private static bool IsAdmin()
|
||||
{
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return false;
|
||||
|
||||
try
|
||||
{
|
||||
var identity = WindowsIdentity.GetCurrent();
|
||||
var principle = new WindowsPrincipal(identity);
|
||||
return principle.IsInRole(WindowsBuiltInRole.Administrator);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddLogging(ILoggingBuilder loggingBuilder)
|
||||
{
|
||||
var config = new NLog.Config.LoggingConfiguration();
|
||||
|
Loading…
Reference in New Issue
Block a user