Working with Objects and Namespaces
上一篇 /
下一篇 2010-03-31 14:01:23
/ 个人分类:VBScript
Namespaces contain objects, and these objects contain properties you can manipulate. Let's use a WMI script, ListWMINamespaces.vbs, to illustrate just how the WMI namespace is organized.
ListWMINamespaces.vbs
Option Explicit
Dim objSWbemServices
Dim colNameSpaces
Dim objNameSpace
Dim strComputer
strComputer = "."Set bjSWbemServices = GetObject("WinMgmts:\\" & strComputer & "\root")
Set colNameSpaces = objSwbemServices.InstancesOf("__NAMESPACE")
For Each objNameSpace In colNameSpaces
WScript.Echo objNameSpace.Name
Next
Knowing the default namespaces gives some information, and though it's helpful, to better map out the WMI namespace, you'll want information about the child namespaces as well. You'll need to implement a recursive query so that you can gain access to the child namespace data.
RecursiveListWMINamespaces.vbs
WScript.Echo(Now)
strComputer = "."
Call EnumNamespaces("root")
Sub EnumNamespaces(strNamespace)
WScript.Echo strNamespace
Set bjSWbemServices = _
GetObject("winmgmts:\\" & strComputer & "\" & strNamespace)
Set colNamespaces = objSWbemServices.InstancesOf("__NAMESPACE")
For Each objNameSpace In colNamespaces
Call EnumNamespaces(strNamespace & "\" & objNamespace.Name)
Next
End sub
WScript.Echo("all done " & Now)
收藏
举报
TAG: