Solved

vbscript: Object Does Not Support This Property or Method

Posted on 2009-05-15
11
1,210 Views
Last Modified: 2012-05-07
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
Comment
Question by:JB4375
  • 5
  • 3
  • 3
11 Comments
 
LVL 17

Expert Comment

by:Jared Luker
Comment Utility
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
 
LVL 1

Author Comment

by:JB4375
Comment Utility
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
 
LVL 17

Expert Comment

by:Jared Luker
Comment Utility
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
 
LVL 17

Expert Comment

by:Jared Luker
Comment Utility
If you put an

On Error Resume Next

on line 68, will your script still function the way you expect it to?
0
 
LVL 17

Accepted Solution

by:
Jared Luker earned 400 total points
Comment Utility
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:JB4375
Comment Utility
I'll test it out with and without a path and see what happens.
Thanks!!
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 100 total points
Comment Utility
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
 
LVL 1

Author Comment

by:JB4375
Comment Utility
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
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
Great!  Good find Jared.....thanks for the assist....

Regards,

Rob.
0
 
LVL 17

Expert Comment

by:Jared Luker
Comment Utility
Rob... you got the assist... I got the answer...

You must be slipping!  :)
0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
LOL!  I have been busy lately, but you got in first, so it's well deserved!

Rob.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Resolve DNS query failed errors for Exchange
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now