Directory Services |
[This documentation is preliminary and subject to change.]
To set the password for an ADAM user, set authentication flags for a non-secure or secure connection, bind to the user, set the port number and method for setting the password, and set the password.
The following VBScript code example uses the GetObject function to connect to the LDAP provider, uses the OpenDSObject method to bind to an ADAM user, uses the SetOption method to set the port number and method, and sets the password with the SetPassword method.
' Set Password of User. Option Explicit Const ADS_SECURE_AUTHENTICATION = 1 Const ADS_USE_SSL = 2 Const ADS_USE_SIGNING = 64 Const ADS_USE_SEALING = 128 Const ADS_OPTION_PASSWORD_PORTNUMBER = 6 Const ADS_OPTION_PASSWORD_METHOD = 7 Const ADS_PASSWORD_ENCODE_REQUIRE_SSL = 0 Const ADS_PASSWORD_ENCODE_CLEAR = 1 Dim intPort ' Port for instance. Dim lngAuth ' Authentication flags. Dim objLDAP ' LDAP provider object. Dim objUser ' User object. Dim strPath ' Binding path. Dim strPort ' Port for instance. Dim strServer ' Server for instance. Dim strUser ' User DN. ' Create LDAP provider. Set objLDAP = GetObject("LDAP:") ' Construct ADAMsPath binding string. ' Change "localhost" to appropriate server. ' Change "389" to LDAP port appropriate for instance, ' or use SSL port (default = "636") for secure connection. ' Change "CN=TestUser,O=Fabrikam,C=US" to DN of user. strServer = "localhost" strPort = "389" intPort = CInt(strPort) strUser = "CN=TestUser,O=Fabrikam,C=US" strPath = "LDAP://" & strServer & ":" & strPort & "/" & strUser WScript.Echo "Bind to: " & strPath ' Set authentication flags. ' For non-secure connection, use LDAP port and ' ADS_USE_SIGNING | ADS_USE_SEALING | ADS_SECURE_AUTHENTICATION ' For secure connection, use SSL port and ' ADS_USE_SSL | ADS_SECURE_AUTHENTICATION lngAuth = ADS_USE_SIGNING Or ADS_USE_SEALING Or _ ADS_SECURE_AUTHENTICATION ' Bind to user object using LDAP port. Set objUser = objLDAP.OpenDsObject(strPath, _ vbNullString, vbNullString, _ lngAuth) On Error Resume Next ' Set password for user. objUser.SetOption ADS_OPTION_PASSWORD_PORTNUMBER, intPort objUser.SetOption ADS_OPTION_PASSWORD_METHOD, _ ADS_PASSWORD_ENCODE_CLEAR ' Note: A password should normally not be entered in code, ' but should be read from a dialog or the console. objUser.SetPassword "ADAMComplexPassword1234" If Err.Number <>0 Then WScript.Echo "Error: Set password failed with error " _ & Hex(Err.Number) Else WScript.Echo "Success: Password set for user" WScript.Echo " " & objUser.ADsPath End If