Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1273
  • Last Modified:

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

0
JB4375
Asked:
JB4375
  • 5
  • 3
  • 3
2 Solutions
 
Jared LukerCommented:
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?
0
 
JB4375Author Commented:
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?
0
 
Jared LukerCommented:
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Jared LukerCommented:
If you put an

On Error Resume Next

on line 68, will your script still function the way you expect it to?
0
 
Jared LukerCommented:
0
 
JB4375Author Commented:
I'll test it out with and without a path and see what happens.
Thanks!!
0
 
RobSampsonCommented:
Hi, as is stated in the article that Jared pointed to, make sure that TsUserEx.dll is installed on the system you are running the script from.

Perhaps though, there's an object that your code is picking up that may not like that property (even though you are filitering by only User accounts....but who knows)....so, what we can do, is just error trap that line to check whether the property exists or not.

See the snippet below for the DO ... LOOP out of your code, with included error trapping....it basically just changed strNewTSPath to "UNKNOWN" if an error occurs.

Regards,

Rob.
' 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
  On Error Resume Next
  strNewTSPath = objUser.TerminalServicesProfilePath
  If Err.Number <> 0 Then
  	strNewTSPath = "<UNKNOWN>"
  End If
  Err.Clear
  On Error GoTo 0
  WScript.Echo strNewHomeLoc
  objRecordSet.MoveNext
  
Loop

Open in new window

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

Regards,

Rob.
0
 
Jared LukerCommented:
Rob... you got the assist... I got the answer...

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

Rob.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now