Richard
Wed May 10 14:59:46 CDT 2006
Hi,
I don't see the problem, but it's hard to say with "On Error Resume Next"
used throughout. There seems to be no need to use the Schema method to
enumerate all properties, since you address them explicitly when you assign
values. I would suggest:
Set objUser = GetObject("LDAP://" & DN)
objUser.Put "homeDrive", HomeDrive
objUser.Put "homeDirectory", HomeDir
On Error Resume Next
objUser.SetInfo
If (Err.Number <> 0) Then
On Error GoTo 0
sMsg = sMsg & Err.Number & vbCrLf
sMsg = sMsg & Err.Description & vbCrLf
sMsg = sMsg & "ERROR: SetInfo failed" & vbCrLf
bError = True
End If
On Error GoTo 0
Only one SetInfo is needed. The disadvantage is that if there is an error,
you don't know which attribute raised the error. You can invoke SetInfo
after every value is assigned, but it seems wasteful, although that could
help isolate a problem. I turn off normal error handling only for statements
I expect could raise an error, then restore normal error handling. In the
above, for example, if the "Set objUser" statement raises an error,
execution will halt, but you will get an error message with a line number,
so you know what happened. And, if that Set objUser failed, there's little
point continueing.
From what you say, the attributes are assigned values (since you see them in
ADUC), they just don't seem to be used until you re-assign them in ADUC. By
testing, I find that if you assign "K" for homeDrive, no error is raised and
ADUC shows the value "K:". If you retrieve the value for homeDrive in code,
however, it is "K". I remember testing in the past and finding that this
does not work, it should be "K:" with the trailing colon. My best guess is
that your variable HomeDrive lacks the trailing colon.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab -
http://www.rlmueller.net
"Kevin" <Kevin@discussions.microsoft.com> wrote in message
news:7AC353DA-DA72-49CA-B865-13A817DA5F2F@microsoft.com...
> "Richard Mueller" wrote:
>> Are you using the LDAP provider and assigning values to the homeDrive and
>> homeDirectory attributes? Also, the homeDrive attribute should be a
>> single
>> letter followed by a colon, such as "H:".
>>
>> If you are using the WinNT provider, the attributes are homeDirDrive and
>> homeDirectory.
>>
>> --
>> Richard
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab -
http://www.rlmueller.net
>
> Richard,
>
> Thanks for the reply, I begin a for loop with this code:
> On Error Resume Next
> Set objUser = GetObject("LDAP://" & DN)
> If Err.Number <> 0 Then
> sMsg = sMsg & Err.Number & vbcrlf
> sMsg = sMsg & Err.Description & vbcrlf
> sMsg = sMsg & "ERROR: Error binding to: " & DN & vbcrlf
> bError = True
> Err.Number = 0
> End If
> Set objClass = GetObject(objUser.Schema)
> For Each property in objClass.OptionalProperties
> objUser.GetInfo
>
> Then using Select Case I alter the properties like this:
> Select Case LCase(property)
> Case LCase("homeDrive")
> objUser.put "homeDrive", HomeDrive
> If Err.Number <> 0 Then
> sMsg = sMsg & Err.Number & vbcrlf
> sMsg = sMsg & Err.Description & vbcrlf
> sMsg = sMsg & "ERROR: objUser.put homeDrive" & vbcrlf
> bError = True
> Err.Number = 0
> End If
> objUser.SetInfo
> If Err.Number <> 0 Then
> sMsg = sMsg & Err.Number & vbcrlf
> sMsg = sMsg & Err.Description & vbcrlf
> sMsg = sMsg & "ERROR: objUser.SetInfo homeDrive" & vbcrlf
> bError = True
> Err.Number = 0
> End If
> Case LCase("homeDirectory")
> objUser.put "homeDirectory", HomeDir
> If Err.Number <> 0 Then
> sMsg = sMsg & Err.Number & vbcrlf
> sMsg = sMsg & Err.Description & vbcrlf
> sMsg = sMsg & "ERROR: objUser.put homeDirectory" & vbcrlf
> bError = True
> Err.Number = 0
> End If
> objUser.SetInfo
> If Err.Number <> 0 Then
> sMsg = sMsg & Err.Number & vbcrlf
> sMsg = sMsg & Err.Description & vbcrlf
> sMsg = sMsg & "ERROR: objUser.SetInfo homeDirectory" & vbcrlf
> bError = True
> Err.Number = 0
> End If
>
> I was finding that four properties were not updating so I moved the
> .GetInfo
> inside of the for loop and ended up adding a .SetInfo to each case. Now
> those
> four properties get updated. As I mentioned in my original post there are
> no
> errors when this executes.