Adding a Connectivity Verifier

This VBScript example creates a new FPCConnectivityVerifier object in the FPCConnectivityVerifiers collection of the Forefront TMG computer. The script includes a single subprocedure, called AddConnectivityVerifier.

This example is included as the AddConnectivityVerifier.vbs script in the Samples\Admin folder of the Forefront TMG Software Development Kit (SDK).

The following procedure lists the steps used to create a new connectivity verifier in the code example that follows.

To create a connectivity verifier

  1. Define values from the FpcConnectivityGroupType and FpcRequestType enumerated types. For more information about using values defined in Forefront TMG enumerated types in scripts, see Using Enumerated Types in Scripts.
  2. Create an instance of the FPC COM object, which provides access to the other Forefront TMG administration COM objects.
  3. Declare an FPCArray object, an FPCConnectivityVerifiers collection, and an FPCConnectivityVerifier object.
  4. Get references to the existing FPCArray object and FPCConnectivityVerifiers collection.
  5. Verify whether an FPCConnectivityVerifier object named DNS Verifier already exists. If it exists, remove it.
  6. Call the Add method of the connectivity verifiers collection to create a new connectivity verifier object named DNS Verifier.
  7. Set the Description and GroupType properties of the new connectivity verifier.
  8. Call the SetConnectivityRequest method to set the server address and request type of the new connectivity verifier.
  9. Use the Threshold property of the new connectivity verifier to set the round-trip time threshold for verification operations to two seconds.
  10. Call the Save method on the connectivity verifiers collection to write the changes to the new connectivity verifier to persistent storage.

The following code can be saved to a .vbs file and run from a command prompt on a computer running Forefront TMG with the Microsoft Firewall service installed.

Sub AddConnectivityVerifier()
	' Define enumeration values.
	Const fpcGroupDNS = 2
	Const fpcPingRequest = 1
	Const serverAddress = "10.0.0.20"
	Const thresholdTime = 2000 ' 2 seconds
	' Create the root object.
	Dim root  ' The FPCLib.FPC root object
	Set root = CreateObject("FPC.Root")
	'Declare the other objects needed.
	Dim tmgArray	' An FPCArray object
	Dim verifiers   ' An FPCConnectivityVerifiers collection
	Dim verifier	' An FPCConnectivityVerifier object
	' Get references to the array object and the connectivity verifiers collection. 
	Set tmgArray = root.GetContainingArray()
	Set verifiers = tmgArray.ConnectivityVerifiers
	' If a connectivity verifier named DNS Verifier already exists, remove it.
	verifiers.Refresh
	On Error Resume Next
	Set verifier = verifiers.Item("DNS Verifier")
	If Err.Number = 0 Then
		WScript.Echo "DNS Verifier exists. Removing it ..."
		verifiers.Remove "DNS Verifier"
		verifiers.Save
	End If
	WScript.Echo "Creating a new connectivity verifier ..."
	Set verifier = verifiers.Add("DNS Verifier")
	' Set the description of the new connectivity verifier.
	verifier.Description = "This connectivity verifier checks connectivity by pinging the DNS server."
	' Set the type of servers with which connectivity is checked.
	verifier.GroupType = fpcGroupDNS
	' Set the server address and request type for connectivity verification requests.
	verifier.SetConnectivityRequest serverAddress, fpcPingRequest
	' Set the round-trip time threshold for verification operations
	verifier.Threshold = thresholdTime
	'Save the changes to the connectivity verifier.
	verifiers.Save
	WScript.Echo "Done!"
End Sub 
AddConnectivityVerifier

Send comments about this topic to Microsoft

Build date: 11/30/2009

© 2008 Microsoft Corporation. All rights reserved.