Example #1
0
    private void mnuModules_Click(object sender, System.EventArgs e)
    {
        // Load the child form to display module information
        frmModules mfrmMod = null;

        try
        {
            ListView lv = this.lvProcesses;

            if (lv.SelectedItems.Count == 1)
            {
                string strProcessId = lv.SelectedItems[0].SubItems[1].Text;
                // Check to see if we got our fake 'total' process
                if (strProcessId == PID_NA)
                {
                    return;
                }
                Process p;
                p = ((Process)(mcolProcesses[Convert.ToInt32(strProcessId)]));

                // Don't enumerate the idle process.
                // You will receive an access denied error.

                if (p.ProcessName == PROCESS_IDLE)
                {
                    return;
                }

                // null to show
                if (p.ProcessName == 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);
        }
    }