Introduction
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.
Background
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
--> GetHDDSerialNumber()
Retrieve the selected HDD's volume serial number.
--> GetHDDFreeSpace()
Retrieve the selected HDD's freespace.
--> GetHDDSize()
Retrieve the selected HDD's size.
--> GetDiskInfo()
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
--> IsIPEnabled()
Retrieve IPEnabled status of the first network adapter.
--> GetMACAddress()
Retrieve MAC Address from first IPEnabled Network Card.
--> GetDefaultIPGateway()
Retrieve the default IP Gateway.
--> isMachineReachable()
Ping specified IP address and report result.
--> GetShareInfo()
Generic method to retrieve Network share info.
==> CPU & Memory Info
--> GetCPUId()
Retrieve processorId from CPU.
--> GetCPUManufacturer()
Retrieve CPU Manufacturer.
--> GetCPUStatus()
Retrieve CPU status.
--> GetCPUCurrentClockSpeed()
Retrieve the CPU's current clock speed.
--> GetRAMCapacity()
Retrieve the total RAM capacity.
==> Operating System Info
--> GetWinServiceList()
Generic method to retrieve name & state information for one or all services.
--> GetWinServiceInfo()
Retrieve a complete list of properties associated with a specified service.
--> GetOSInfo()
Retrieve a complete list of operating system object names and properties or
Retrieve the value of a specified OS attribute.
--> GetRegistryInfo()
Retrieve value of a specified registry attribute.
--> GetEventLog()
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.
History
11-10-09 - Initial release of code
P.S.: Interesting date, isn't it.