private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { // Clean up the child form if it's there if (!(mfrmMod == null)) { try { mfrmMod.Owner = null; mfrmMod.ParentProcess = null; mfrmMod.Close(); mfrmMod.Dispose(); mfrmMod = null; } catch (Exception exp) { MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void mnuModules_Click(object sender, System.EventArgs e) { // Load the child form to display module information frmModules mfrmMod = null; try { if (lvProcesses.SelectedItems.Count == 1) { string strProcessId = lvProcesses.SelectedItems[0].GetRow().Cells["PID"].Value as String; int ItemIndex = lvProcesses.SelectedItems[0].GetRow().Position; // Check to see if we got our fake 'total' process if (strProcessId == PID_NA) { return; } Process p; p = ((Process)(mcolProcesses[ItemIndex])); // Don't enumerate the idle process. // You will receive an access denied error. if (p.ProcessName == PROCESS_IDLE) { MessageBox.Show(PROCESS_IDLE); return; } // null to show if (p.ProcessName == PROCESS_SYSTEM) { MessageBox.Show(PROCESS_SYSTEM); // return; } p.Refresh(); // Finally check to see if we can even // Get the module count. // if not, no point in going further. try { int i = p.Modules.Count; } catch { MessageBox.Show("Sorry, you are not authorized to read this information.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // if the form is not available, load it if (mfrmMod == null) { mfrmMod = new frmModules(); } // Pass the selected process mfrmMod.ParentProcess = p; // Get the module data mfrmMod.RefreshModules(); // Show the form mfrmMod.ShowDialog(this); } } catch (Exception exp) { MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } }