Partager via


Obtaining Class Instances

If you establish a direct connection with a cluster node (see Making Direct Connections), you can obtain instances of Network Load Balancing (NLB) provider classes as follows:

The following code snippet demonstrates how to obtain instances of NLB provider classes. For a more detailed code example, see NLBScriptLib.vbs.

'Set configuration data.
strClusterIP = "172.50.66.14"
strHostID = "1"
strDIP = "172.50.35.12"
strKey = strClusterIP & ":" & strHostID
strNamespace = "root\MicrosoftNLB"
strUser = "Administrator"
strPassword = ""
strPortNumber = "65535"

'Make a direct connection.
Set oLoc = CreateObject("WbemScripting.SWbemLocator")
Set oSvc = oLoc.ConnectServer(strDIP, _
                              strNamespace, _
                              strUser, _
                              strPassword)
oLoc.Security_.ImpersonationLevel = 3

'Get a node instance.
Set oNodes = oSvc.InstancesOf ("MicrosoftNLB_Node")
For Each oNode in oNodes
    ' The first one is the one we want
    Exit For
Next

'Get a node setting instance.
Set oNodeSettings = oSvc.InstancesOf ("MicrosoftNLB_NodeSetting")
For Each oNodeSetting in oNodeSettings
    ' The first one is the one we want
    Exit For
Next

'Get a port rule instance.
oNodeSetting.GetPortRule CLng(strPortNumber), oPortRule

WScript.Echo oPortRule.Name

Set oPortRule = Nothing
Set oNodeSetting = Nothing
Set oNodeSettings = Nothing
Set oNode = Nothing
Set oNodes = Nothing
Set oSvc = Nothing
Set oLoc = Nothing