Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why doesn't this quite work?
I would also like to know how to ask Microsoft to include some specific methods such as reading the number of processes active and inactive on a computer?
How would I turn this to a web method?
How do I control the information that is posted across from the browser to the application and the other way round?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace TestOne
{
    class Program
    {
        static void Main(string[] args)
        {
            EnumMods(0);
            Console.ReadKey();
        }

        static void EnumMods(int PID)
        {
            Process theProc = null;
            try
            {
                theProc = Process.GetProcessById(PID);
            }
            catch (ArgumentException ex) { 
                Console.WriteLine(ex.Message);
                return;
            }
            Console.WriteLine("Here are the loaded modules for: {0}", theProc.ProcessName);
            ProcessModuleCollection theMods = theProc.Modules;
            foreach (ProcessModule pm in theMods)
            {
                String info = string.Format("-> Mod Name: {0}", pm.ModuleName);
                Console.WriteLine(info);
            }
        }
    }
}


The exception is:
Error
Here are the loaded modules for: Idle
 
Unhandled Exception: System.ComponentModel.Win32Exception: Unable to enumerate t
he process modules.
at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolea
n firstModuleOnly)
at System.Diagnostics.ProcessManager.GetModuleInfos(Int32 processId)
at System.Diagnostics.Process.get_Modules()
at TestOne.Program.EnumMods(Int32 PID) in c:\users\slyth_000\documents\visual
studio 2010\Projects\TestOne\TestOne\Program.cs:line 29
at TestOne.Program.Main(String[] args) in c:\users\slyth_000\documents\visual
studio 2010\Projects\TestOne\TestOne\Program.cs:line 13
Press any key to continue . . .
Posted
Updated 18-Jun-14 22:44pm
v2

I do not know what you intention is for listing all running process in Windows.
Perhaps some remote status in Web ?

But anyway. If you want to list all running process and list all the loaded modules for a process, you need elevated permission.

A normal user cannot list all running processes in Windows.

A good inspiration is to look at the program Process Explorer[^] from Microsoft. It can help you to verify what you are able to see.

And for a Web method, web sites.. What is your plan? REST API, SOAP, ASP.NET Site?
 
Share this answer
 
v2
Error
Here are the loaded modules for: Idle

Unhandled Exception: System.ComponentModel.Win32Exception: Unable to enumerate t
he process modules.
at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolea
n firstModuleOnly)
at System.Diagnostics.ProcessManager.GetModuleInfos(Int32 processId)
at System.Diagnostics.Process.get_Modules()
at TestOne.Program.EnumMods(Int32 PID) in c:\users\slyth_000\documents\visual
studio 2010\Projects\TestOne\TestOne\Program.cs:line 29
at TestOne.Program.Main(String[] args) in c:\users\slyth_000\documents\visual
studio 2010\Projects\TestOne\TestOne\Program.cs:line 13
Press any key to continue . . .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900