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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript - terminal server user profile path 2

Status
Not open for further replies.

MatrixReloaded

Technical User
Apr 16, 2003
3
AU
Can anyone help me with the code for extracting the terminal server user profile path please?
I can get the normal profile path but not the terminal server one.

MsgBox ("Logon Name: " & UserObj.Name & vbCrLf & _
"Full Name: " & UserObj.Fullname & vbCrLf & _
"Profile: " & UserObj.Profile & vbCrLf & _
"Description: " & UserObj.Description & vbCrLf & _
"LoginScript: " & UserObj.LoginScript & vbCrLf & _
"LastLogin: " & UserObj.LastLogin & vbCrLf & _
"WTSProfile: " & UserObj.?????)

Thanks
 
If you have Windows 2K3 Active Directory, see

However, Windows 2K Active Directory does NOT expose to ADSI the Terminal Service User properties. See

Here's a solution I used a while back,

Download the tscmd utility from

Use the following script modified to fit your configuration

Code:
sOutFile = "C:\termserv.txt"
sTSCmdPath = "C:\tscmd.exe"
sServer = "YourServer"
sADPath ="DC=Your,DC=Domain,DC=Com"

bCscript = (InStr(1,WScript.FullName,"CSCRIPT.EXE",1)>0)
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile(sOutfile,True)
Set oDomain = GetObject("LDAP://CN=Users," & sADPath)
oDomain.Filter = Array("User")
For Each oUser in oDomain
  If bCscript Then Wscript.StdOut.Write oUser.samAccountName
  sExec = "cmd /c " & sTSCmdPath & " " & sServer & " """
  sExec = sExec  & oUser.samAccountName & """ TerminalServerProfilePath"
  Set oExec = oShell.Exec(sExec)
  Do While oExec.Status = 0
    WScript.Sleep 250
  Loop
  If bCscript Then Wscript.StdOut.WriteLine vbTab & oExec.Status
  oFile.Write oUser.samAccountName & vbTab & oExec.StdOut.ReadAll
Next
oFile.Close
Set oFile = Nothing
Set oFSO = Nothing
Set oShell = Nothing

I would also recommend running it thru Cscript to avoid the flicker each time the tscmd is executed

cscript "C:\yourscript.vbs"

Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top