Link to home
Start Free TrialLog in
Avatar of JB4375
JB4375Flag for United States of America

asked on

vbscript: Object Does Not Support This Property or Method

I've written a script that creates a new user account, based on another account. It works fine except when I leave in the line 74 where it attempts to capture the Terminal Services Profile path. At this point I get the following error:

Microsoft VBScript runtime error: Object doesn't support this property or method: 'TerminalServicesProfilePath'

Below is the top part of the effected code.

Thanks!
Option Explicit
 
' Declarations
Dim strSimilarUser, strDomain
Dim objConnection, objCommand, objRecordSet ' declarations for connection to AD
Dim strCategory, strClass, strTarget, strFilter ' declarations for filter for AD query
Dim strLocation, objUser, objGroup, Group, objMemberOf ' declarations for similar user attributes
Dim strNewLocation, strNewUserID, strNewFirstName, strNewMI, strNewLastName, strEmail ' declarations for new user attributes
Dim strNewDisplayName, strNewDescription, strNewHomeDir, strNewScript, strNewTSPath ' declarations for new user attributes
Dim objDestOU, objNewUser ' declarations for creating new user
Dim strPossibleUserName, intNumberofRecords, strAssignID, strExistingUser ' declarations for generating user ID and validating
Dim strAlphabet, strNumbers, i, strReturn, strPWChar(), strNewPassword ' declarations for generating password
Dim objFSO, objLetter ' declarations for letter to user
Dim objMailBox, strMDB, strFirstInitial, strAF, strGL, strMR, strSZ ' declarations for mailbox
Dim objEmail, strHTML, strNewHomeLoc, objFolder
 
' Create connection to AD
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
 
 
' Specify user to copy and new user parameters and generate user ID
strSimilarUser = InputBox("Enter the username of the similar user", "Create Similar User")
strDomain = "dc=domain,dc=com"
strNewFirstName = InputBox("Enter the first name of the new user", "Create Similar User")
strNewMI = InputBox("Enter the middle initial of the new user", "Create Similar User")
strNewLastName = InputBox("Enter the last name of the new user", "Create Similar User")
strEmail = MsgBox("Do You Want an Email Account?", vbYesNo, "Create Similar User")
 
If strNewMI = "" Then
  strNewDisplayName = strNewFirstName & " " & strNewLastName
Else
  strNewDisplayName = strNewFirstName & " " & strNewMI & ". " & strNewLastName
End If
 
WScript.Echo "*** Processing " & strNewDisplayName & " ***"
GenerateID()
GeneratePassword()
strFirstInitial = Mid(strNewUserID, 1, 1)
strMDB = GetMDB()
WScript.Echo ""
WScript.Echo "    * Querying user attributes For " & strSimilarUser & "..."
 
 
' Define filter to query the similar user parameters
strCategory = "(objectCategory=Person)"
strClass = "(ObjectClass=User)"
strTarget = "(cn=" & strSimilarUser & ")"
strFilter = strCategory & strClass & strTarget
 
 
' Query AD with filter defined above
objCommand.CommandText = "<LDAP://mdc1/" & strDomain & ">;(&" & strFilter & ")" & ";DistinguishedName;subtree"
Set objRecordSet = objCommand.Execute
 
 
' Handle the query results, assign the new user the similar user's parameters
Do Until objRecordSet.EOF
  
  WScript.Echo "    * Assigning attributes to " & strNewDisplayName & VbCrLf
  strLocation = objRecordSet.Fields("DistinguishedName")
  Set ObjUser = GetObject("LDAP://dc/" & strLocation )'
  
  objMemberOf = objUser.GetEx("MemberOf")
  
  strNewLocation = Replace(strLocation, "CN=" & strSimilarUser & ",","")
  strNewDescription = objUser.Description
  strNewHomeDir = Replace(objUser.HomeDirectory, strSimilarUser, strNewUserID)
  strNewHomeLoc = Replace(objUser.HomeDirectory, strSimilarUser,"")
  strNewScript = ObjUser.ScriptPath
  strNewTSPath = objUser.TerminalServicesProfilePath '***Here is the problem line****
  WScript.Echo strNewHomeLoc
  objRecordSet.MoveNext
  
Loop

Open in new window

Avatar of Jared Luker
Jared Luker
Flag of United States of America image

I don't see anything wrong with the code right off hand.  Is the TerminalServicesProfilePath field empty on the user that it's trying to gather info from?
Avatar of JB4375

ASKER

Yes... and that's what is frustrating because less than half of the users actually use it. I have code out side the loop that stated if the string equals nothing then do this etc....
How would I handle this in the loop?
I just tried it out on a user of mine that has nothing in that field and it did not error out like that, so being blank is not the issue.
If you put an

On Error Resume Next

on line 68, will your script still function the way you expect it to?
ASKER CERTIFIED SOLUTION
Avatar of Jared Luker
Jared Luker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JB4375

ASKER

I'll test it out with and without a path and see what happens.
Thanks!!
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JB4375

ASKER

Turns out I didn't have the TSUserEx.dll. File installed. Good find. Awarding points for the error trapping code as well.
Thanks guys!!
Great!  Good find Jared.....thanks for the assist....

Regards,

Rob.
Rob... you got the assist... I got the answer...

You must be slipping!  :)
LOL!  I have been busy lately, but you got in first, so it's well deserved!

Rob.