Click here to Skip to main content
11,410,750 members (63,945 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#5
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 18-Jun-14 23:12pm
jon-801.4K
Edited 18-Jun-14 23:44pm
Kim Togo26.4K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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?
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 . . .
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 239
1 Sascha Lefévre 85
2 Dave Kreskowiak 80
3 Maciej Los 68
4 RyanDev 50
0 Sergey Alexandrovich Kryukov 8,885
1 OriginalGriff 6,915
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | Last Updated 19 Jun 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100