. Net WMI programming preliminary test

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.