Website of Markus Griesser
Latest Update: 29.12.2007
This is one of my bigger projects, so it will get its own site.
Now I restarted the development of my Taskmanager in C# and as I mentioned
in my Daily Notes, it was very easy to design the UI. At least this is
one big advantage of .NET. Due to evaluating the system near functions
for enumerating processes, services, memory status etc. I had to
realise, that they are not or only partial available via .NET. Enumerating
service is available in .NET, but not completly. You get all services,
their names, description and status, but you will not get the startup
type...
Puh, not good so far. So I switched to WMI (WQI in my case). Thise is a
.NET independent construct for getting system specific information, but
can be very beautiful integrated to your C# project. Look at this:
using System.Management;
namespace Taskmanager{
class ProcessIter{
private ManagementObjectCollection GetServices(){
ManagementObjectSearcher query = new ManagementObjectSearcher
("SELECT * FROM Win32_Service ");
ManagementObjectCollection collection = query.Get();
return collection;
}
public bool EnumServices(ref MyService []allservices){
ManagementObjectCollection services = GetServices();
foreach(ManagementObject service in services){
// Do something unimportant
string serviceState = service["State"].ToString();
string serviceType = service["ServiceType"].ToString();
string startmode = service["StartMode"].ToString();
// Again do something
}
return true;
}
}
}
As you can see, it is very easy. A reference for all WMI classes can be
found on msdn.
MSDN Link
02.01.2006: Today I wanted to add Windows shut down functionality, but
found out that the ExitWindowsEx function seems not to be implemented in
.NET in version 2.0. Another function I have to import. Do not like it,
because now more than the half of all system near functions are dll
imports and not native .NET.
Well, enough from the incrash, now the download of the executable.
Taskmanager .NET Executable, Size: 24.3 KB