Missing home dir when account created by vbscript

May 10th, 2006 - 02:19 pm ET by Kevin | Report spam
When I create an account using vbscript I also create the home dir for the
user and populate the homeDir properties of the account. There are no errors
creating the directory and there are no errors populating the homeDir
property of the account. Using Active Directory Users and Computer (ADUC) I
can see that the account was created and that the home dir was set properly.
Checking the drive for the dir reveals it is created and the rights are
assigned correctly.

The problem is at login. When you login with one of these accounts the user
does not get a mapping to their home dir. Yet if they use the run cmd they
can open the dir and utilize it.

We suspect it has something to do with what gets input to the homeDir
property but I'm unable to determine that there is anything wrong with it.

Interestingly if I modify the home dir property in ADUC (so the apply button
becomes active) and then switch it back to what was there then click apply,
when the user logs in their home dir appears correctly for them.

Any ideas?
email Follow the discussionReplies 4 repliesReplies Make a reply

Replies

#1 Kevin
May 10th, 2006 - 06:21 pm ET | Report spam
"Richard Mueller" wrote:
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



Richard,

Thanks, it was in fact the drive designation. The input file was missing the
":". As for the numerous .SetInfo, I found that I had to have them or
multiple properties did not get set even though there were no errors
reported. Perhaps it was the home drive that was causing that, I'll review it
and retest it to see if I can go back to a single .SetInfo.

Thanks for your help.

Similar topics