473,466 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 5470

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Colin Brown | last post by:
Recently I was looking for remote management tools and came across "Windows Management Instrumentation". There is a python interface available: http://tgolden.sc.sabren.com/python/wmi.html I...
5
by: Jean-Sébastien Guay | last post by:
Hello, I'm pretty new to Python, though I have a fair bit of experience with C/C++, Java, Perl, PHP and others. I installed Tim Golden's wmi module...
2
by: Paul Gronka | last post by:
I've got a VB.NET windows application (written in VS .NET 2003) that makes a call to WMI for retrieving the MAC Address from the client's PC. It works on 4 out of the 5 PC's tested so far. All...
9
by: | last post by:
Hi All, I have allready tried to ask a similar question , but got no answer until now. In the meantime, I found, that I cannot understand some thread-settings for the Main() function . If I use...
3
by: Roy Osherove | last post by:
Hi folks. I have an ASP.Net application that runs a .Net dll that uses WMI and ADSI(both managed) to connect to a given IIS root and search through it. When not using the ASP.Net client, but...
0
by: Ewart MacLucas | last post by:
generated some WMI managed classes using the downloadable extensions for vs2003 from mircrosoft downloads; wrote some test code to enumerate the physicall processors and it works a treat, but a...
7
by: Salvador | last post by:
Hi, I am using WMI to gather information about different computers (using win2K and win 2K3), checking common classes and also WMI load balance. My application runs every 1 minute and reports...
9
by: Adrian Dev | last post by:
Hi, I have succesfully used a ManagementScope object to get WMI information about workstations on the current domain using "//xp10/root/cimv1". But if I make a request to a workstation on a...
5
by: kyosohma | last post by:
Hi, I am trying to create a post logon script which does various tasks, like setup a printer based on location. While most of it works very fast, I have a second Python script that I run that...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.