Ejemplo n.º 1
0
        void captureWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            CaptureArguments captureArguments = (CaptureArguments)e.Argument;

            using (FileStream crashDumpFileStream = File.Create(captureArguments.FilePath))
            {
                bool success = MiniDumpFile.Create(
                    captureArguments.ProcessHandle,
                    (uint)captureArguments.ProcessId,
                    crashDumpFileStream.SafeFileHandle,
                    captureArguments.MiniDumpType,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    IntPtr.Zero);

                if (!success)
                {
                    int lastError = Marshal.GetLastWin32Error();

                    // Neat way to avoid the pain of calling FormatMessage.
                    // You can create a new instance of Win32Exception without calling GetLast*Error first,
                    // but I prefer this way as it's more obvious what's happening
                    Win32Exception lastErrorException = new Win32Exception(lastError);

                    MessageBox.Show(lastErrorException.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 2
0
        private void btnCapture_Click(object sender, EventArgs e)
        {
            #region Validate user data
            if (this.TargetProcess == null)
            {
                MessageBox.Show("Please select a process.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.wizardControl1.SelectedIndex = TP_PROCESS_LIST;

                return;
            }

            if (this.HasMiniDumpTypeSelected == false)
            {
                MessageBox.Show("Please select the data to include in the minidump.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.wizardControl1.SelectedIndex = TP_MINIDUMP_OPTIONS;

                return;
            }

            if (this.txtSaveLocation.Text == "")
            {
                MessageBox.Show("Please enter a file name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            #endregion

            CaptureArguments captureArguments = new CaptureArguments();

            // Remote process might be running with admin rights
            try
            {
                captureArguments.ProcessHandle = TargetProcess.Handle;
            }
            catch (Win32Exception w32ex)
            {
                if (w32ex.HResult == E_ACCESSDENIED) // access denied
                {
                    MessageBox.Show("'" + TargetProcess.ProcessName + "' is running with elevated privileges, please restart Minidump Explorer with elevated privileges and try again.",
                                    "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }

                throw;
            }

            captureArguments.ProcessId    = this.TargetProcess.Id;
            captureArguments.FilePath     = this.txtSaveLocation.Text;
            captureArguments.MiniDumpType = this.MiniDumpType;

            BackgroundWorker captureWorker = new BackgroundWorker();
            captureWorker.DoWork             += captureWorker_DoWork;
            captureWorker.RunWorkerCompleted += captureWorker_RunWorkerCompleted;
            captureWorker.RunWorkerAsync(captureArguments);

            _progressDialog.ShowDialog(this);
        }