This VBScript example creates a new FPCURLSet object in the FPCURLSets collection of the Forefront TMG computer, adds sites to the URL set, creates a new FPCPolicyRule object representing an access rule, and adds the new URL set to the objects referenced in the URLSets property of the new access rule. The script includes a single subprocedure, called AddRuleAndUrlSet.
This example is included as the AddRuleAndUrlSet.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 URL set and an access rule in the code example that follows.
To add an access rule
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 AddRuleAndUrlSet() ' Define enumeration values. Const fpcInclude = 0 Const fpcSpecifiedProtocols = 1 ' 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 policyrules ' An FPCPolicyRules collection Dim urlsets ' An FPCURLSets collection Dim urlset ' An FPCURLSet object Dim newrule ' An FPCPolicyRule object ' Get references to the array object, the policy ' rules collection, and the URL sets collection. Set isaArray = root.GetContainingArray() Set policyrules = isaArray.ArrayPolicy.PolicyRules Set urlsets = isaArray.RuleElements.URLSets WScript.Echo "Creating a new URL set containing sites to be blocked ..." Set urlset = urlsets.Add("Blocked Web Sites") urlset.Add "http://www.northwindtraders.com" urlset.Add "http://www.widgets.com" urlset.Save WScript.Echo "Creating a new access rule ..." Set newrule = policyrules.AddAccessRule("Deny Access to Some Web Sites") ' Define the source for the new access rule. newrule.SourceSelectionIPs.Networks.Add "External", fpcInclude ' Add the new destination URL set to the objects referenced ' by the URLSets property of the new access rule. newrule.AccessProperties.URLSets.Add "Blocked Web Sites", fpcInclude 'Set the protocols to HTTP and HTTPS. newrule.AccessProperties.SpecifiedProtocols.Add "HTTP", fpcInclude newrule.AccessProperties.SpecifiedProtocols.Add "HTTPS", fpcInclude newrule.AccessProperties.ProtocolSelectionMethod = fpcSpecifiedProtocols ' Set the user set to which the rule applies. newrule.AccessProperties.UserSets.Add "All Users", fpcInclude ' Save the changes to the new access rule. policyrules.Save WScript.Echo "Done!" End Sub AddRuleAndUrlSet
Send comments about this topic to Microsoft
Build date: 11/30/2009
© 2008 Microsoft Corporation. All rights reserved.