Click here to Skip to main content
Click here to Skip to main content

WMI Helper Library For Accessing System Information

, 11 Oct 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
I recently came across the System.Management namespace and was surprised at the array of useful functionality encapsulated within it. Examples using the namespace were scattered and narrowly focused and I think having a single location demonstrating this diverse functionality may be of use to some o

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. 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

kannankeril

United States United States
ASP.Net Developer
Seattle, WA

Comments and Discussions

 
GeneralNot to defer from your work but... PinmemberTaylorMichaelL12-Oct-09 3:56 
GeneralThank you for the heads up... Pinmemberkannankeril20-Oct-09 8:18 
GeneralMy vote of 2 Pinmembergaurav_verma_mca11-Oct-09 22:13 
GeneralPlease click on the link labeled "Download SysInfo - 57.42 KB"... Pinmemberkannankeril20-Oct-09 8:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 12 Oct 2009
Article Copyright 2009 by kannankeril
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid