471,350 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

WMI: Determine Running Tasks

Using WMI, how do I retrieve the list of running applications on a pc? If
you open up task manager and click on the applications tab, I am trying to
retrieve the task name and the status. I looked high and low in the WMI
documentation and unable to find a class that returns this info.

Any help is appreciated.

#region List all properties from WMI Query
// WMI Documentation
//
http://msdn.microsoft.com/library/de...re_classes.asp
string wmiQuery = "Select * from Win32_Process";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
Console.WriteLine("=============================== =================");
Console.WriteLine(wmiQuery);
Console.WriteLine("=============================== =================");
foreach (ManagementObject service in searcher.Get())
{
Console.WriteLine("=============================== =================");
Console.WriteLine("SERVICE: " + service.ToString());
Console.WriteLine("=============================== =================");
foreach ( PropertyData s in service.Properties)
{
Console.WriteLine("Name: {0} Value: {1}", s.Name.ToString(),
service[s.Name.ToString()]);
}
Console.ReadLine();

}
Console.WriteLine("=============================== =================");
Console.WriteLine("PRESS ENTER TO EXIT");
Console.WriteLine("=============================== =================");
Console.ReadLine();
#endregion
Dec 19 '05 #1
2 5353

Chris Fink wrote:
Using WMI, how do I retrieve the list of running applications on a pc? If
you open up task manager and click on the applications tab, I am trying to
retrieve the task name and the status. I looked high and low in the WMI
documentation and unable to find a class that returns this info.


Technically, you can't. However, if you are trying to reproduce task
manager,
you might try something like this:

Process[] myProcesses = Process.GetProcesses();
int idx = 0;
foreach(Process myProcess in myProcesses)
{
if ( myProcess.MainWindowHandle != IntPtr.Zero )
{
Console.WriteLine(myProcess.MainWindowTitle);
idx ++;
}
}
Console.WriteLine("{0} Processes found\n", idx );

Basically, I'm looking at any process that has a main window. This
won't
work 100% of the time, but I think it works well enough to be useful.

Matt

Dec 19 '05 #2
Hi Matt,

This should get me by. Thanks.

"Matt" wrote:

Chris Fink wrote:
Using WMI, how do I retrieve the list of running applications on a pc? If
you open up task manager and click on the applications tab, I am trying to
retrieve the task name and the status. I looked high and low in the WMI
documentation and unable to find a class that returns this info.


Technically, you can't. However, if you are trying to reproduce task
manager,
you might try something like this:

Process[] myProcesses = Process.GetProcesses();
int idx = 0;
foreach(Process myProcess in myProcesses)
{
if ( myProcess.MainWindowHandle != IntPtr.Zero )
{
Console.WriteLine(myProcess.MainWindowTitle);
idx ++;
}
}
Console.WriteLine("{0} Processes found\n", idx );

Basically, I'm looking at any process that has a main window. This
won't
work 100% of the time, but I think it works well enough to be useful.

Matt

Dec 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Colin Brown | last post: by
5 posts views Thread by Jean-Sébastien Guay | last post: by
3 posts views Thread by Roy Osherove | last post: by
reply views Thread by Ewart MacLucas | last post: by
7 posts views Thread by Salvador | last post: by
9 posts views Thread by Adrian Dev | last post: by
5 posts views Thread by kyosohma | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.