WMI Tutorial – II

As mentioned in the previous post in this series, there are two distinct mechanisms that can be used to establish a connection to WMI on a local/remote computer:

1) SWbemLocator object and
2) SWbemServices Object

Both the mechanisms are same except 2 differences. SwbemLocator object has to be used to connect to WMI if:

a) username and password is required to connect to remote computer (if local machine account has less privileges than that of remote machine)
b) WMI script is required to run from within the webpage

The sample statements illustrating both the connection mechanisms:



strComputer = "."
 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")


strComputer = "PC-Vijay"
 Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
 Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, "root\cimv2", "domain\vijay", "password")

WMI Object Flow

WMI Connection Mechanism

As seen in both of the above illustrations, both return SWbemServices object after connecting to cimv2 WMI namespace on strComputer. After obtaining the reference to an SWbemServices object, any of the several methods can be called to connect to Managed Object in order to query it. It can return either of the SWbemObjectSet, SWbemObject, or SWbemEventSource object where each object represents the different entities listed below.

i) SWbemObject: Managed Object
ii) SWbemObjectset: Collection of Managed Objects
iii) SWbemEventSource: Collection of Events from event query

In the next post, we will examine sample script line by line in order to understand its components.

Advertisements
Tagged with: , , , , , , , , , , , ,
Posted in wmi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog Stats
  • 168,130 hits
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 796 other followers

%d bloggers like this: