connect2sandeep

How to enumerate the running processes in a system using platform invoke. Please provide a code snippet.
Thanks



Re: Common Language Runtime listing the running processes in system using platform invoke (c#)

TaylorMichaelL

You wouldn't since .NET already provides a managed API. The problem is that different OSes use different techniques for enumerating processes. Stick with the managed API for this. BTW it is Process.GetProcesses.

Michael Taylor - 3/8/07
http://p3net.mvps.org





Re: Common Language Runtime listing the running processes in system using platform invoke (c#)

Ollie Riches

I don't understand why you would want to do this using interop when you can use any number of ways to do this in .Net, one example is WMI:

using System;
using System.Collections.Generic;
using System.Text;

using System.Management;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string query = "SELECT Name, ProcessId, Caption, ExecutablePath FROM Win32_Process";
            string scope = @"
\\.\root\CIMV2";
                       
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection processes = searcher.Get();

            foreach (ManagementObject mo in processes)
            {
                Console.WriteLine(mo["Name"].ToString());
            }
        }
    }
}

 

HTH

Ollie Riches






Re: Common Language Runtime listing the running processes in system using platform invoke (c#)

Christian Liensberger - MSP

.NET provides the Process class that allows you to do the same:

Process[] processes = Process.GetProcesses();






Re: Common Language Runtime listing the running processes in system using platform invoke (c#)

connect2sandeep

Well,
I specifically asked for a PInvoke implementation because i wanted to see how PInvoke can be used to call Win32 APIs.





Re: Common Language Runtime listing the running processes in system using platform invoke (c#)

Christian Liensberger - MSP

PInvoke.net can be a great resource for you. It has a lot of platform invoke samples on it. Also samples on how to get the processes or enumerate the windows etc.