This VBScript example runs a query to find the active sessions on a Forefront TMG computer and then displays the active sessions found. The script includes a single subprocedure, called DisplayActiveSessions.
This example is included as the ActiveSessions.vbs script in the Samples\Admin folder of the Forefront TMG Software Development Kit (SDK).
The following procedure lists the steps used to find and display active sessions in the code example that follows.
To find and display active sessions
The following code can be saved to a .vbs file and run on a computer running Forefront TMG with the Microsoft Firewall service installed. We recommend running this script from a command prompt using the CScript command.
Sub DisplayActiveSessions() ' Define an enumeration value. Const fpcSessionFound = 0 Const bufferSize = 10000 ' Create the root object. Dim root ' The FPCLib.FPC root object Set root = CreateObject("FPC.Root") ' Declare the other objects needed. Dim isaArray ' An FPCArray object Dim sessionmonitor ' An FPCSessionsMonitor collection Dim filter ' An FPCFilterExpressions collection Dim session ' An FPCSessionsMonitorEntry object ' Get references to the array object and the sessions monitor collection. Set isaArray = root.GetContainingArray() Set sessionmonitor = isaArray.SessionsMonitors.SessionsMonitorFirewall ' Create a filter expressions collection. Set filter = CreateObject("FPC.FPCFilterExpressions") ' Start a query to find the active sessions. sessionmonitor.ExecuteQuery filter, bufferSize WScript.Echo "Finding the active sessions ... Please wait a few seconds." Dim Index Index = 1 On Error Resume Next Do Set session = sessionmonitor.Item(Index) ' An E_PENDING (0x80070002) error is raised when ' the index points beyond the end of the current list of sessions. If Err.Number <> 0 Then WScript.Echo "All existing sessions have been retrieved." Exit Do End If ' An FPCSessionMonitorEntry object can be ' related to various session events. Here we ' are interested only in entries whose Event ' property equals fpcSessionFound, which ' indicates a session that existed when the ' query started. Display the client IP address ' of each session found. If session.Event = fpcSessionFound Then WScript.Echo "Session with: " & session.ClientIP End If Index = Index + 1 Loop Until Err.Number <> 0 Err.Clear ' Stop the query. sessionmonitor.EndQuery WScript.Echo "The query has been stopped." WScript.Echo "Done!" End Sub DisplayActiveSessions
Send comments about this topic to Microsoft
Build date: 11/30/2009
© 2008 Microsoft Corporation. All rights reserved.