.NET WMI programming initial test

zhaozj2021-02-16  87

Some of the knowledge of WMI scripting programming has just been studied in Blog, I also wrote a note "WMI Minute - Windows Management Scripting". Today, I learned that WMI programming is implemented by several classes under System.Management. My WMI Minute records the first WMI routine written with VBScript is about how to get the total memory of this unit. The procedure is as 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.totalphysicalMemoryNext

I decided to change it into .Net implementation, I didn't encounter any difficulties, I got it in a few minutes, huh, huh -

Just build a WinForm, add the reference to System.Management.dll,

Imports System.Management

Add code in Form_Load:

??????? DIM OWMI AS NEW ManagementClass ("Win32_LogicalMemoryConfiguration") ??????? DIM COLM As ManagementObjectCollection = OWMI.GETINSTANCES () ??????? DIM OBJM AS ManagementObject ????? ?? for Each Objm in colm ??????????? msgbox ("Total Memory:" Objm.properties ("TotalphysicalMemory). Value.toString ()) ??????? NEXT

WMI is really useful, through it you can read and control information about operating systems, services, networks, processes. Today is just a trial, and write some detailed explanations and more practical examples.

转载请注明原文地址:https://www.9cbs.com/read-11695.html

New Post(0)