private static void DisplayError(Exception ex, ProcessStartResult status)
            {
                if (!(Package.GetGlobalService(typeof(SVsGeneralOutputWindowPane)) is IVsOutputWindowPane outputPane))
                {
                    return;
                }

                outputPane.Activate();

                if (status == ProcessStartResult.AuthDenied)
                {
                    outputPane.OutputString(
                        "Visual Studio restart operation was cancelled by the user." + Environment.NewLine);
                }
                else
                {
                    var sb = new StringBuilder();
                    sb.AppendLine(
                        "An exceptions has been thrown while trying to start an elevated Visual Studio, see details below.");
                    sb.AppendLine(ex.ToString());

                    var diagnostics = sb.ToString();

                    outputPane.OutputString(diagnostics);
                    var log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog;
                    log?.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, "Equilogic.VsRestart", diagnostics);
                }

                //EnvDTE.OutputWindow.OutputWindow.Parent.Activate();
            }
Example #2
0
    private static ProcessStartResult CreateProcessStartResult(bool waitForExit, uint waitTimeout,
                                                               ProcessInformation processInfo, bool started)
    {
        uint exitCode  = 0;
        var  hasExited = false;

        if (started && waitForExit)
        {
            var waitResult = Win32Api.WaitForSingleObject(processInfo.Process, waitTimeout);
            if (waitResult == WaitForSingleObjectResult.WAIT_OBJECT_0)
            {
                Win32Api.GetExitCodeProcess(processInfo.Process, ref exitCode);
                hasExited = true;
            }
        }
        var result = new ProcessStartResult()
        {
            ExitCode  = (int)exitCode,
            Started   = started,
            HasExited = hasExited
        };

        return(result);
    }
            private static ProcessStartResult StartProcessSafe(ProcessStartInfo startInfo, Action <Exception, ProcessStartResult> exceptionHandler)
            {
                ProcessStartResult result = ProcessStartResult.Ok;

                try
                {
                    Process.Start(startInfo);
                }
                catch (Exception ex)
                {
                    result = ProcessStartResult.Exception;
                    var winex = ex as System.ComponentModel.Win32Exception;

                    // User has denied auth through UAC
                    if (winex != null && winex.NativeErrorCode == 1223)
                    {
                        result = ProcessStartResult.AuthDenied;
                    }

                    exceptionHandler(ex, result);
                }

                return(result);
            }
            private static void DisplayError(Exception ex, ProcessStartResult status)
            {
                IVsOutputWindowPane outputPane = Package.GetGlobalService(typeof(SVsGeneralOutputWindowPane)) as IVsOutputWindowPane;

                outputPane.Activate();

                if (status == ProcessStartResult.AuthDenied)
                {
                    outputPane.OutputString("Visual Studio restart operation was cancelled by the user." + Environment.NewLine);
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("An exceptions has been trown while trying to start an elevated Visual Studio, see details below.");
                    sb.AppendLine(ex.ToString());

                    string diagnostics = sb.ToString();

                    outputPane.OutputString(diagnostics);
                    IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog;
                    log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, "MidnightDevelopers.VsRestarter", diagnostics);
                }

                //EnvDTE.OutputWindow.OutputWindow.Parent.Activate();
            }