Add Method of the IFPCComputerSets Interface

The Add method creates a new FPCComputerSet object in the collection and returns a reference to it.



  [in]   BSTR Name,
  [out]  IFPCComputerSet** ppNewItem


Required. BSTR that specifies the name of the new computer set.

Address of an interface pointer that on return points to the new IFPCComputerSet interface created.

Return Value

This method can return one of the following:

[Visual Basic]


Function Add( _
  ByVal Name As String _
) As FPCComputerSet


Required. String that specifies the name of the new computer set.

Return Value

This method returns a reference to an FPCComputerSet object if successful. Otherwise, an error is raised that can be intercepted by using an error handler.

Example Code

This VBScript script creates a new computer set with the user-specified name if it does not exist and imports all the names and IP addresses of the computers listed in a text file to the list of computers in the user-specified computer set.
Option Explicit
'Define the constants needed
Const Error_FileNotFound = &H80070002
Const Error_NotIpAddress = &HC0040302
Const ForReading = 1
' Define the delimiter used in the text file.
Dim delimiter		 ' A String
delimiter = vbTab	 
Sub Main(args)
	If(args.Count <> 2) Then
	End If
	AddComputersToComputerSet args(0), args(1)
End Sub
Sub AddComputersToComputerSet(fileName, computerSetName)
	' 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 computerSets	' An FPCComputerSets collection
	Dim computerSet	 ' An FPCComputerSet object
	Dim computers	 ' An FPCComputers collection
	Dim fso			 ' A FileSystem object
	Dim fileStream	' A TextStream object
	Dim textRead		' A String
	Dim textArray	 ' An Array
	' Get references to the array object 
	' and the computer sets collection.
	Set isaArray = root.GetContainingArray()
	Set computerSets = isaArray.RuleElements.ComputerSets
	' Retrieve the specified computer set.
	On Error Resume Next
	Set computerSet = computerSets.Item(computerSetName)
	If Err.Number = Error_FileNotFound Then
		WScript.Echo "The " & computerSetName & " computer set does not exist. " _
			& "Creating it ..."
		Set computerSet = computerSets.Add(computerSetName)
	End If
	On Error GoTo 0
	' Retrieve the collection of computers included in the computer set.
	Set computers = computerSet.Computers
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set fileStream = fso.OpenTextFile(fileName, ForReading)
	On Error Resume Next
	Do While fileStream.AtEndOfStream <> True
		textRead = fileStream.ReadLine
		If textRead <> "" Then
			textArray = Split(textRead, delimiter)
			If UBound(textArray) <> 1 Then
				WScript.Echo "An improperly formed line was found in the text file."
				WScript.Echo "No changes will be saved."
			End If
			computers.Item textArray(0)
			If Err.Number = Error_FileNotFound Then
				computers.Add textArray(0), textArray(1)
				If Err.Number = Error_NotIpAddress Then
					WScript.Echo textArray (1) & " is not a valid IP address."
					WScript.Echo "Adding " &  textArray(0) & " " _ 
						& textArray(1) & " ..."
				End If
			End If
		End If
	On Error GoTo 0
	' Save the changes.
	WScript.Echo "Done!"
End Sub 
Sub Usage()
	WScript.Echo "Usage:" & VbCrLf _
		& "  CScript " & WScript.ScriptName & " FileName CsName" & VbCrLf _
		& "" & VbCrLf _
		& "  FileName - Text file containing the list of computers" & VbCrLf _
		& "  CsName   - Computer set to which the computers will be added" 
End Sub


Client Requires Windows Vista or Windows XP.
Server Requires Windows Server 2008.
Version Requires Forefront Threat Management Gateway (TMG).

Declared in Msfpccom.idl.


Requires Msfpccom.dll.

See Also


Send comments about this topic to Microsoft

Build date: 11/30/2009

© 2008 Microsoft Corporation. All rights reserved.