Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone tell me why this doesn't work? 2

Status
Not open for further replies.

keybrdcowboy

IS-IT--Management
Aug 31, 2004
96
US
I keep getting a "object doesn't support this property" error. I know what the error means, but I don't know why I keep getting it, or better yet, what I need to do to fix it. Can anyone help? The error is for the line that says to get the user's home drive and change it...

Here's the code:

Option Explicit
Dim newDirectory, fsoIn, inFile, fsoOut, outFile, arruserPath, strDirPath, strUserName
Dim objUser, strHomeDrive, strHomeDirPath, strTest

Const inFilename = "usernames.txt"
Const outFilename = "ChangeHomeDirPath.log"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

' Open the input file
Set fsoIn = CreateObject("scripting.filesystemobject")
Set inFile = fsoIn.OpenTextFile(inFilename, ForReading, True)

' Open the log file (append mode) and timestamp the entry
Set fsoOut = CreateObject("scripting.filesystemobject")
Set outFile = fsoOut.OpenTextFile(outFilename, ForAppending, True)
outFile.writeline (Now & vbTab & "Starting script...")

While Not inFile.AtEndOfStream
arrUserPath = Split(inFile.Readline, vbTab, -1, 1)
' arrUserPath(0) contains the user names
strUserName = arrUserPath(0)

strHomeDrive = "Z:"
strHomeDirPath = "\\server\" & strUserName

' Connect to the user account in AD
Set objUser = GetObject("WinNT://" & strUserName & "user")
'strTest = objUser.homedirectory
'wscript.echo strtest
If Err.Number <> 0 Then
outFile.writeline Now & vbTab & "Error connecting to " & strUserName & " --- " & Err.Description
Err.Clear
ErrorOccurred = True
Else
' Set the path for the account
On Error Resume Next
objUser.put "HomeDrive", "Z:"
On Error Goto 0
objUser.HomeDirectory = strHomeDirPath
objUser.SetInfo
If Err.Number <> 0 Then
outFile.writeline Now & vbTab & "Error setting home directory path for " & strUserName & " --- " & Err.Description
Err.Clear
ErrorOccurred = True
Else
outFile.writeline (Now & vbTab & "Home directory set for " & strUserName)
End If
End If
Wend

' Clean up the environment
outFile.writeline (Now & vbTab & "Ending script...")
inFile.close
outFile.close

If ErrorOccurred Then
msgbox "Script completed with errors. Please check the log file."
Else
MsgBox "Script completed successfully."
End If

 
Replace this:
GetObject("WinNT://" & strUserName & "user")
By this:
GetObject("WinNT://" & strUserName & ",user")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello keybrdcowboy,

Further to what correctly pointed out by PHV, you have also to explicitly spell out the domain for domain user (and for local, computername).
[tt] "WinNT://" & domainname & "/" & strUserName & ".user"[/tt]
Your strUserName most probably won't have a structure like domainname\username as I see you set your strHomeDirPath like what you show up there.

regards - tsuji
 
Further notes:

Take a careful look of the locations of the directive "on error resume next". It does not look right, for sure.

- tsuji
p.s. Correct my type "[red],[/red]user" above.
 
also you will always get an error returned from the GetObject command if the Username no longer exists in AD.
 
Good stuff guys. Once again you guys have come through. Here's my next question though. I am trying to learn this Vbscript thing, and I can get most of my scripts to work, however I don't really understand why they work, and that bugs me. Do you guys know of any tutorial from start to finish web sites or books that I should check out? I ecspecially don't understand the connecting to active directory lines. What's the difference between using WinNT and LDAP? Why do the fields have different names depending on which one you use? Know any websites where that is explained? Once again, thanks for all your help. I'm starting a new script here in a min, so i'll proabbly be back.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top