473,554 Members | 3,181 Online
Bytes | Software Development & Data Engineering Community
+ 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";
ManagementObjec tSearcher searcher = new ManagementObjec tSearcher(wmiQu ery);
Console.WriteLi ne("=========== =============== =============== =======");
Console.WriteLi ne(wmiQuery);
Console.WriteLi ne("=========== =============== =============== =======");
foreach (ManagementObje ct service in searcher.Get())
{
Console.WriteLi ne("=========== =============== =============== =======");
Console.WriteLi ne("SERVICE: " + service.ToStrin g());
Console.WriteLi ne("=========== =============== =============== =======");
foreach ( PropertyData s in service.Propert ies)
{
Console.WriteLi ne("Name: {0} Value: {1}", s.Name.ToString (),
service[s.Name.ToString ()]);
}
Console.ReadLin e();

}
Console.WriteLi ne("=========== =============== =============== =======");
Console.WriteLi ne("PRESS ENTER TO EXIT");
Console.WriteLi ne("=========== =============== =============== =======");
Console.ReadLin e();
#endregion
Dec 19 '05 #1
2 5479

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.GetProc esses();
int idx = 0;
foreach(Process myProcess in myProcesses)
{
if ( myProcess.MainW indowHandle != IntPtr.Zero )
{
Console.WriteLi ne(myProcess.Ma inWindowTitle);
idx ++;
}
}
Console.WriteLi ne("{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.GetProc esses();
int idx = 0;
foreach(Process myProcess in myProcesses)
{
if ( myProcess.MainW indowHandle != IntPtr.Zero )
{
Console.WriteLi ne(myProcess.Ma inWindowTitle);
idx ++;
}
}
Console.WriteLi ne("{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
7190
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 was amazed how easy it became to access just about anything under the hood (later versions of NT, 2000, XP) using a couple of lines of code! If you...
5
3174
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 (http://tgolden.sc.sabren.com/python/wmi.html), in the hopes it would help me list and work with services on my Win32 machine. Now, everything seems fine except for one thing : Listing...
2
14011
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 the workstations are DELLs running XP SP1a with the 1.1 .NET Framework. The following line of code generates an exception on the one PC: Dim oMac...
9
6310
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 the attribute for the Main() function, I get "access denied error", if I use a ManagementEventWatcher to connect to the local machine to receive...
3
3626
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 running from a winforms project - I can connect to both local and remote machines. However, when using the ASP.Net project - I get an "Access denied"...
0
3327
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 question.. The code fails with the error that: "Additional information: COM object that has been separated from its underlying RCW can not be used."...
7
6921
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 the status of the machines. Upon we follow the .NET object lifetime recommendations the application is constantly consuming more memory! The problem...
9
7753
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 sub-domain, the command fails to connect with "Access denied". Do I need to alter the string somehow to include the sub domain name or could this be a...
5
5552
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 scans the PC using WMI (among other things) and writes the following to a database: Name, Username, Machine, IP, Login Date,CPU,Memory. The problem...
0
7596
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7560
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7887
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5431
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5152
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3545
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2015
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 we have to send another system
1
1130
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.