This can be done in code through WMI. I found a tool from Microsoft that creates code for it.
The WMI code writer allows you to create VBScript, C #, and VB.NET code that uses WMI to perform management tasks, such as querying for management data, executing a method from the WMI class, or receiving event notifications using WMI.
You can download here .
source
share