Some time ago, I just learned some knowledge about WMI Script Programming and wrote a note on the blog "WMI minute-Windows Management script learning". Today I learned how to program WMI in. NET through several classes in system. Management. My WMI minute records the first WMI routine written in VBScript about how to obtain the total memory of the local machine.ProgramAs follows:
Strcomputer = "."
Set wbemservices = GetObject ("winmgmts: //" & strcomputer)
Set wbemobjectset = wbemservices. instancesof ("win32_logicalmemoryconfiguration ")
For each wbemobject in wbemobjectset
??? Wscript. Echo "total physical memory (Kb):" & wbemobject. totalphysicalmemory
Next
I decided to change it to the. NET implementation. I didn't have any difficulties. I just got it done in a few minutes --
Create a winform and add the reference of system. Management. dll,
Imports system. Management
Add in form_loadCode:
??????? Dim owmi as new managementclass ("win32_logicalmemoryconfiguration ")
??????? Dim Colm as managementobjectcollection = owmi. getinstances ()
??????? Dim objm as managementobject
??????? For each objm in Colm
??????????? Msgbox ("total local memory:" + objm. properties ("totalphysicalmemory"). value. tostring ())
??????? Next
WMI is really useful. You can use it to read and control information about the operating system, Service, Network, and process. Today, I just want to test it, I will write more detailed and more practical examples in the next day.