Ejemplo n.º 1
0
        public async Task Start(Connection connection, ElevationRequest elevationRequest)
        {
            if (Settings.SecurityEnforceUacIsolation && !elevationRequest.NewWindow)
            {
                throw new Exception("TokenSwitch mode not supported when SecurityEnforceUacIsolation is set.");
            }

            try
            {
                TokenSwitcher.ReplaceProcessToken(elevationRequest);

                await connection.ControlStream.WriteAsync(Constants.TOKEN_SUCCESS).ConfigureAwait(false);

                connection.DisconnectedWaitHandle.WaitOne(); // Wait until client receives the response before closing.
            }
            catch (Exception ex)
            {
                Logger.Instance.Log($"{ex.ToString()}", LogLevel.Debug);
                await connection.ControlStream
                .WriteAsync(
                    $"{Constants.TOKEN_ERROR}Server Error: Setting token failed.\r\n{ex.Message}\r\n{Constants.TOKEN_ERROR}")
                .ConfigureAwait(false);
            }
            finally
            {
                Native.ConsoleApi.SetConsoleCtrlHandler(ConsoleHelper.IgnoreConsoleCancelKeyPress, false);
                await connection.FlushAndCloseAll().ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
        public Task <int> Execute()
        {
            var elevationRequest = new ElevationRequest()
            {
                IntegrityLevel  = InputArguments.GetIntegrityLevel(),
                TargetProcessId = ProcessId,
            };

            TokenSwitcher.ReplaceProcessToken(elevationRequest);
            return(Task.FromResult(0));
        }