コード例 #1
0
ファイル: RunCommand.cs プロジェクト: reanimat0r/gsudo
        /// <summary>
        /// Single elevation mode means no service is kept running. Also the command line shown in UAC is a little bit more explicit.
        /// </summary>
        /// <param name="elevationRequest"></param>
        /// <returns></returns>
        private async Task <int> RunUsingSingleUseElevation(ElevationRequest elevationRequest)
        {
            Logger.Instance.Log($"Using Console mode {ElevationRequest.ConsoleMode.TokenSwitch}", LogLevel.Debug);
            TokenSwitchRenderer renderer = null;

            try
            {
                renderer = new TokenSwitchRenderer(null, elevationRequest);
            }
            catch (Exception ex)
            {
                Logger.Instance.Log($"TokenSwitchRenderer mode failed with {ex.ToString()}. Fallback to Attached Mode", LogLevel.Debug);
                elevationRequest.Mode = ElevationRequest.ConsoleMode.Attached; // fallback to attached mode.
                return(await RunUsingElevatedService(elevationRequest).ConfigureAwait(false));
            }

            if (StartSingleUseElevatedService(elevationRequest.TargetProcessId))
            {
                return(await renderer.GetResult().ConfigureAwait(false));
            }
            else
            {
                renderer.TerminateProcess();
                return(Constants.GSUDO_ERROR_EXITCODE);
            }
        }
コード例 #2
0
        /// <summary>
        /// Single elevation mode means no service is kept running. Also the command line shown in UAC is a little bit more explicit.
        /// </summary>
        /// <param name="elevationRequest"></param>
        /// <returns></returns>
        private async Task <int> RunUsingSingleUseElevation(ElevationRequest elevationRequest)
        {
            Logger.Instance.Log($"Using Console mode {ElevationRequest.ConsoleMode.TokenSwitch}", LogLevel.Debug);

            var renderer = new TokenSwitchRenderer(null, elevationRequest);

            if (StartSingleUseElevatedService(elevationRequest.TargetProcessId))
            {
                return(await renderer.GetResult().ConfigureAwait(false));
            }
            else
            {
                renderer.TerminateProcess();
                return(Constants.GSUDO_ERROR_EXITCODE);
            }
        }