Browse Source

Fixed run as admin not working on windows

Krzysztof Krysiński 4 months ago
parent
commit
0a2087a837

+ 0 - 5
src/PixiEditor.Linux/LinuxProcessUtility.cs

@@ -12,11 +12,6 @@ public class LinuxProcessUtility : IProcessUtility
         throw new NotImplementedException("Running as admin is not supported on Linux");
     }
 
-    public Process RunAsAdmin(string path, string args, bool createWindow)
-    {
-        throw new NotImplementedException("Running as admin is not supported on Linux");
-    }
-
     public bool IsRunningAsAdministrator()
     {
         return Environment.IsPrivilegedProcess;

+ 1 - 10
src/PixiEditor.MacOs/MacOsProcessUtility.cs

@@ -6,22 +6,13 @@ namespace PixiEditor.MacOs;
 internal class MacOsProcessUtility : IProcessUtility
 {
     public Process RunAsAdmin(string path, string args)
-    {
-        return RunAsAdmin(path, args, true);
-    }
-
-    public Process RunAsAdmin(string path, string args, bool createWindow)
     {
         ProcessStartInfo startInfo = new ProcessStartInfo
         {
             FileName = path,
             Verb = "runas",
             Arguments = args,
-            UseShellExecute = createWindow,
-            CreateNoWindow = !createWindow,
-            RedirectStandardOutput = !createWindow,
-            RedirectStandardError = !createWindow,
-            WindowStyle = createWindow ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden
+            UseShellExecute = true
         };
 
         Process p = new Process();

+ 0 - 1
src/PixiEditor.OperatingSystem/IProcessUtility.cs

@@ -5,7 +5,6 @@ namespace PixiEditor.OperatingSystem;
 public interface IProcessUtility
 {
     public Process RunAsAdmin(string path, string? args);
-    public Process RunAsAdmin(string path, string? args, bool createWindow);
     public bool IsRunningAsAdministrator();
     public Process ShellExecute(string toExecute);
     public Process ShellExecute(string toExecute, string args);

+ 1 - 10
src/PixiEditor.Windows/WindowsProcessUtility.cs

@@ -8,22 +8,13 @@ namespace PixiEditor.Windows;
 public class WindowsProcessUtility : IProcessUtility
 {
     public Process RunAsAdmin(string path, string args)
-    {
-        return RunAsAdmin(path, args, true);
-    }
-
-    public Process RunAsAdmin(string path, string args, bool createWindow)
     {
         ProcessStartInfo startInfo = new ProcessStartInfo
         {
             FileName = path,
             Verb = "runas",
             Arguments = args,
-            UseShellExecute = createWindow,
-            CreateNoWindow = !createWindow,
-            RedirectStandardOutput = !createWindow,
-            RedirectStandardError = !createWindow,
-            WindowStyle = createWindow ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden
+            UseShellExecute = true
         };
 
         Process p = new Process();

+ 0 - 5
src/PixiEditor/Helpers/ProcessHelper.cs

@@ -14,9 +14,4 @@ internal static class ProcessHelper
     {
         return IOperatingSystem.Current.ProcessUtility.IsRunningAsAdministrator();
     }
-
-    public static void RunAsAdmin(string path, string? args, bool showWindow)
-    {
-        IOperatingSystem.Current.ProcessUtility.RunAsAdmin(path, args, showWindow);
-    }
 }

+ 1 - 1
src/PixiEditor/ViewModels/SubViewModels/UpdateViewModel.cs

@@ -272,7 +272,7 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
     {
         try
         {
-            ProcessHelper.RunAsAdmin(updaterPath, startAfterUpdate ? "--startOnSuccess" : null, false);
+            ProcessHelper.RunAsAdmin(updaterPath, startAfterUpdate ? "--startOnSuccess" : null);
             Shutdown();
         }
         catch (Win32Exception)