Solved

vbscript: Object Does Not Support This Property or Method

Posted on 2009-05-15
11
1,234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 17

Expert Comment

by:Jared Luker
ID: 24397361
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
ID: 24397389
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
ID: 24397530
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 17

Expert Comment

by:Jared Luker
ID: 24397536
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
ID: 24397571
0
 
LVL 1

Author Comment

by:JB4375
ID: 24398484
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
ID: 24409202
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
ID: 24413053
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
ID: 24417291
Great!  Good find Jared.....thanks for the assist....

Regards,

Rob.
0
 
LVL 17

Expert Comment

by:Jared Luker
ID: 24418181
Rob... you got the assist... I got the answer...

You must be slipping!  :)
0
 
LVL 65

Expert Comment

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

Rob.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

740 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