diff --git a/src/gsudo/ProcessHosts/AttachedConsoleHost.cs b/src/gsudo/ProcessHosts/AttachedConsoleHost.cs index a54ad8e6..fe6dbb07 100644 --- a/src/gsudo/ProcessHosts/AttachedConsoleHost.cs +++ b/src/gsudo/ProcessHosts/AttachedConsoleHost.cs @@ -1,10 +1,10 @@ using System; -using System.Security.Principal; +using System.Security.Principal; using System.Threading; using System.Threading.Tasks; using gsudo.Helpers; using gsudo.Rpc; -using Windows.Win32; +using Windows.Win32; using static gsudo.Native.ConsoleApi; namespace gsudo.ProcessHosts @@ -16,7 +16,7 @@ namespace gsudo.ProcessHosts // This mode is not enabled unless you use --attached. class AttachedConsoleHost : IProcessHost { - public bool SupportsSimultaneousElevations { get; } = true; + public bool SupportsSimultaneousElevations { get; } = false; public async Task Start(Connection connection, ElevationRequest elevationRequest) { @@ -35,19 +35,16 @@ public async Task Start(Connection connection, ElevationRequest elevationRequest try { - try - { - System.Environment.CurrentDirectory = elevationRequest.StartFolder; + try + { + System.Environment.CurrentDirectory = elevationRequest.StartFolder; } catch (UnauthorizedAccessException ex) - { + { throw new ApplicationException($"User \"{WindowsIdentity.GetCurrent().Name}\" can not access current directory \"{elevationRequest.StartFolder}\""); - } - - var process = Helpers.ProcessFactory.StartAttached(elevationRequest.FileName, elevationRequest.Arguments); + } - PInvoke.FreeConsole(); - PInvoke.AllocConsole(); + var process = Helpers.ProcessFactory.StartAttached(elevationRequest.FileName, elevationRequest.Arguments); WaitHandle.WaitAny(new WaitHandle[] { process.GetProcessWaitHandle(), connection.DisconnectedWaitHandle }); if (process.HasExited) @@ -84,7 +81,7 @@ public async Task Start(Connection connection, ElevationRequest elevationRequest finally { PInvoke.SetConsoleCtrlHandler(ConsoleHelper.IgnoreConsoleCancelKeyPress, false); - //PInvoke.FreeConsole(); + PInvoke.FreeConsole(); await connection.FlushAndCloseAll().ConfigureAwait(false); } }