473,668 Members | 2,457 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 5484

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
7194
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 have privileged access to remote computers you can interrogate them as well. My attempts to modify...
5
3179
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 services!
2
14032
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 As New System.Management.ManagementClass("Win32_NetworkAdapterConfiguration") The error it...
9
6321
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 events. Is there anybody out there, how possibly can explain why this happens?? If I remove this...
3
3630
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" exception. This happens when calling the ManagementScope.Connect() method.
0
3339
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." if I make a call to pc.Count before iterating though the objects. Dim d As New...
7
6929
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 is on the ManagementObjectSearch, upon we Dispose the object it seems that is not releasing the...
9
7765
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 rights issue ? Thanks in advance, Adrian
5
5570
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 I have is that since I import WMI, it takes a long time and we have users complaining about it. So...
0
8889
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8652
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7391
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2782
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
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.