The System.Management namespace covers the Windows Management Instrumentation (WMI) framework. It encapsulates a wide variety of information gathering and management functionality with respect to PC hardware, OS components/services info and Networking protocols/status info. It possibly does more but these are the topics that I have investigated in the short period that I have been exploring it.
The code required to use WMI functionality in your projects is quite simple. However, most sources that I came across focused on one or few narrowly focused functions forcing a prospective reader to troll multiple sources to get at desired information. I thought that a broader treatment of WMI in one single location would serve some of us. More specifically, my idea was to create a library that offered a simple and readily accessible interface to WMI.
Using the code
The attached solution accordingly comprises a WMI wrapper and sample code demonstrating its use. My goal is that the interested reader should be able to download the zip file, extract the solution, open and execute it within VS2008. Upon gaining some familiarity, the user can then reference the library within their own projects and call on its functionality as per requirement.
The following is a complete list of functionality currently offered by the library.
==> Harddisk Info
Retrieve the selected HDD's volume serial number.
Retrieve the selected HDD's freespace.
Retrieve the selected HDD's size.
Generic method to retrieve information on all local disk drives
or a specific drive
or a specific property for all local drives
or a specific property for a specific drive.
==> Network Info
Retrieve IPEnabled status of the first network adapter.
Retrieve MAC Address from first IPEnabled Network Card.
Retrieve the default IP Gateway.
Ping specified IP address and report result.
Generic method to retrieve Network share info.
==> CPU & Memory Info
Retrieve processorId from CPU.
Retrieve CPU Manufacturer.
Retrieve CPU status.
Retrieve the CPU's current clock speed.
Retrieve the total RAM capacity.
==> Operating System Info
Generic method to retrieve name & state information for one or all services.
Retrieve a complete list of properties associated with a specified service.
Retrieve a complete list of operating system object names and properties or
Retrieve the value of a specified OS attribute.
Retrieve value of a specified registry attribute.
Returns a filtered list of events from a specific eventlog. The list can be
filtered by Logfile, Event Type and Source Name.
I won't claim much originality in the writing of this code and have attempted to document the original reference where applicable. Like many of us I have given up on trying to reinvent the wheel and frequently scour the web for solutions to new problems. It is my hope that the attached code provides the solution to one or more of your problems.
Without swearing any concrete promises, I promise to expand the library to include requested and relevant functionality over time. Your feedback and criticism are always welcome.
11-10-09 - Initial release of code
P.S.: Interesting date, isn't it.