AddLdapUser Method of the IFPCNonWindowsUsers2 Interface

The AddLdapUser method creates a new FPCNonWindowsUser object in the collection for an LDAP user and returns a reference to it.

[C++]

Syntax

HRESULT AddLdapUser(
  [in]   BSTR Username,
  [in]   BSTR LdapServerUsername,
  [in]   BSTR LdapServerUserPassword,
  [in]   BSTR LdapServerSetName,
  [out]  IFPCNonWindowsUser** ppNonWindowsUser
);

Parameters

Username
Required. BSTR that specifies the user name of the new LDAP user.
LdapServerUsername
Required. BSTR that specifies the user name that will be presented for accessing an LDAP server in the LDAP server set specified in the LdapServerSetName parameter.
LdapServerUserPassword
Required. BSTR that specifies the password that will be presented for accessing an LDAP server in the LDAP server set specified in the LdapServerSetName parameter.
LdapServerSetName
Required. BSTR that specifies the name of the LADP server set to be used for the new LDAP user.
ppNonWindowsUser

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

Return Value

This method can return one of the following:

[Visual Basic]

Syntax

Function AddLdapUser( _
  ByVal Username As String, _
  ByVal LdapServerUsername As String, _
  ByVal LdapServerUserPassword As String, _
  ByVal LdapServerSetName As String _
) As FPCNonWindowsUser

Parameters

Username
Required. String that specifies the user name of the new LDAP user.
LdapServerUsername
Required. String that specifies the user name that will be presented for accessing an LDAP server in the LDAP server set specified in the LdapServerSetName parameter.
LdapServerUserPassword
Required. String that specifies the password that will be presented for accessing an LDAP server in the LDAP server set specified in the LdapServerSetName parameter.
LdapServerSetName
Required. String that specifies the name of the LADP server set to be used for the new LDAP user.

Return Value

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

Example Code

This VBScript script adds LDAP users to the users set specified on the command line using the user name and password provided on the command line to access an LDAP server in the LDAP server set specified on the command line. Note that the user name for accessing an LDAP server must be specified in the domain\user-name format.
Option Explicit
'Define the constants needed
Const Error_FileNotFound = &H80070002
Const Error_AccessDenied = &H80070005
Const Error_IncorrectParameter = &H80070057
Const Error_AlreadyExists = &H800700B7
Main(WScript.Arguments)
Sub Main(args)
	If(args.Count <> 4) Then
		Usage()
	End If
	AddLdapUsers args(0), args(1), args(2), args(3)
End Sub
Sub AddLdapUsers(userSetName, ldapServerSet, userName, password)
	' 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 userSets	 ' An FPCUserSets collection
	Dim userSet	' An FPCUserSet object
	Dim nwUsers	' An FPCNonWindowsUsers collection
	Dim input		' A String
	' Get references to the array object and the user sets collection.
	Set isaArray = root.GetContainingArray()
	Set userSets = isaArray.RuleElements.UserSets
	' Get a reference to the user set specified by the user.
	On Error Resume Next
	Set userSet = userSets.Item(userSetName)
	If err.Number = Error_FileNotFound Then
		WScript.Echo "The user set " & userSetName & " does not exist. Aborting ..."
		WScript.Quit
	End If
	On Error GoTo 0
	' Get a reference the collection of non-Windows users in the user set.
	Set nwUsers = userSet.NonWindowsUsers
	Do
		input = InputBox("Name of the LDAP user to add (or Quit to exit)", ,"Quit")
		If input = "Quit" Then
			Exit Do
		End If
		On Error Resume Next
		nwUsers.AddLdapUser input, userName, password, ldapServerSet
		If err.Number = Error_IncorrectParameter Then
			WScript.Echo "The LDAP server set specified does not exit, " _
				& "or the operation was canceled."
			Err.Clear
			WScript.Quit
		ElseIf err.Number = Error_AccessDenied Then
			WScript.Echo "Access to the LDAP server was denied."
			Err.Clear
			WScript.Quit
		ElseIf err.Number = Error_AlreadyExists Then
			WScript.Echo "The user " & input & " is already an LDAP user."
			Err.Clear
		ElseIf err.Number <> 0 Then
			WScript.Echo "An error occurred: 0x" & Hex(Err.Number) & " " & Err.Description
			Err.Clear
			WScript.Quit
		Else
			WScript.Echo "The user " & input & " was added as an LDAP user."
		End If
		On Error GoTo 0
	Loop
	' Save changes.
	userSet.Save			
	WScript.Echo "Done!"
End Sub 
Sub Usage()
	WScript.Echo "Usage:" & VbCrLf _
		& "  " & WScript.ScriptName & " UserSet LdapServerSet UserName Password" & VbCrLf _
		& "" & VbCrLf _
		& "  UserSet - Name of the user set" & VbCrLf _
		& "  LdapServerSet - Name of the LDAP server set" & VbCrLf _
		& "  UserName - User name for accessing an LDAP server" & VbCrLf _
		& "  Password - Password for accessing an LDAP server" 
	WScript.Quit
End Sub

Remarks

If a user name is specified in the domain\user-name format in the Username parameter, the domain name will be ignored.

Requirements

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

Declared in Msfpccom.idl.

DLL

Requires Msfpccom.dll.

See Also

FPCNonWindowsUsers


Send comments about this topic to Microsoft

Build date: 11/30/2009

© 2008 Microsoft Corporation. All rights reserved.