Do you use Sisoft Sandra or similar programs?
Let's spend 15 minutes and write the skeleton of its program of similar functionality.
A small lyrical digression. First you need to say that Windows has such an interesting thing as WMI. This is nothing more than an add-on to the Windows Driver Model, which will allow us without any problems to find out the whole story of our favorite computer.
So let's start:
First you need to fasten the necessary assembly to our project. Namely, System.Management. In using we will write System.Management and System.Management.Instrumentation.
')
Then we go
to read about what WMI actually provides us. But this is somehow not at all interesting, let's finally start writing a program. Moreover, it is simple and everything will become clear in the course of writing. To do this, go straight to the
description of the WMI classes. I decide to choose
Win32 Classes , especially since it is through them that we will receive information about the hardware.
Here is an example of how easy it is to get information about logical drives:
public static void PrintDisksStat ()
{
// first, we need to create an object - request, in which we actually need to indicate what and where we want to get
ObjectQuery DiskQuery = new System.Management.ObjectQuery ("select FreeSpace, FileSystem, Size, Name, VolumeName, VolumeSerialNumber from Win32_LogicalDisk where DriveType = 3");
// Information "seeker", approximate analogue of DataSet
ManagementObjectSearcher DiskSearcher = new ManagementObjectSearcher (DiskQuery);
ManagementObjectCollection DiskCollection = DiskSearcher.Get ();
foreach (ManagementObject DiskInfo in DiskCollection)
{
Console.WriteLine ("Disk Name:" + DiskInfo ["Name"]. ToString ());
Console.WriteLine (“Disk Size:” + DiskInfo [“Size”]. ToString ());
Console.WriteLine ("Volume Name:" + DiskInfo ["VolumeName"]. ToString ());
Console.WriteLine (“File system:” + DiskInfo [“FileSystem”]. ToString ());
Console.WriteLine (“Free Space:” + DiskInfo [“FreeSpace”]. ToString ());
Console.WriteLine (“Volume Serial Number:” + DiskInfo [“VolumeSerialNumber”]. ToString ());
}
}
I think that comments are superfluous. Although I got excited - be sure to
read what else is interesting in the Win32_LogicalDisk class.
Similarly, you can get information about the processor.
public static void PrintProcessorStat ()
{
ObjectQuery ProcessorQuery = new System.Management.ObjectQuery ("select Name, Caption, Description, L2CacheSize, Manufacturer, Revision from Win32_Processor where ProcessorType = 3");
ManagementObjectSearcher ProcessorSearcher = new ManagementObjectSearcher (ProcessorQuery);
ManagementObjectCollection ProcessorCollection = ProcessorSearcher.Get ();
foreach (ManagementObject ProcessorInfo in ProcessorCollection)
{
Console.WriteLine ("Processor Information;");
Console.WriteLine ("Name:" + ProcessorInfo ["Name"]. ToString ());
Console.WriteLine ("Tag:" + ProcessorInfo ["Caption"]. ToString ());
Console.WriteLine ("Description:" + ProcessorInfo ["Description"]. ToString ());
Console.WriteLine (“Level 2 cache:” + ProcessorInfo [“L2CacheSize”]. ToString ());
Console.WriteLine (“Manufacturer:” + ProcessorInfo [“Manufacturer”]. ToString ());
Console.WriteLine (“Revision:” + ProcessorInfo [“Revision”]. ToString ());
}
}
Again, I can say read MSDN.
That's all that I wanted to tell. Other information is also easy to obtain. you only need to spend some time studying the documentation.
Update: Examples are given in C # 2.0. IDE - VS2005 Express