Imports System
Imports System.Management
Module Module1
Public Sub Main()
Dim strComputer As String = "." , i, intValue As Integer
Dim colItems, objWMIService, objItem
objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
For i = 1 To 5
Threading.Thread.Sleep(1000)
colItems = objWMIService.ExecQuery("Select * From Win32_PerfRawData_PerfProc_Process Where Name = 'devenv'" )
For Each objItem In colItems
intValue = objItem.HandleCount
Console.WriteLine("打开的句柄数 :" & intValue)
Next
Next
End Sub
End Module
使用Getobject
函数创建对象多用于脚本中,所以参数为WMI 脚本库的标记名 "winmgmts:" 和目标电脑名,上述的strComputer="." 相当于localhost ,若在远程计算机上执行则需将 "." 改这相应的计算机名。
其中:
ManagementObject:单个管理对象
ManagementClass:单个管理类
ManagementObjectSearcher:查询 管理对象及管理类的集合
ManagementEventWatcher:监视来自 WMI 的事件
ManagementQuery:用作所有查询类的基础。
也可以从脚本中创建:
Set oLocator = CreateObject("WbemScripting.SWbemLocator") ' New SWbemLocator
If Err.Number <> 0 Then
MsgBox "Windows Management (WMI) 不能被创建" & Err.Description
WScript.Quit(0)
End If
----------------------------------------------------------------------
set locator = createobject(" WbemScripting.SwbemLocator")
set server = locator.ConnectServer ("\\192.168.0.1\root\cimv2","username","password")
set p_obj = server.execquery("select * form Win32_operatingsystem")
for each p_objswbem in p_obj
p_objswbem.reboot ' 从新启动
next
WMI 的有关概述请参考 MSDN 或 http://www.csdn.net/develop/Article/19/19157.shtm
没有评论:
发表评论