Get terminal service profile path from AD user in code

1

I'm trying to read the terminal service profile path for a selected AD user using the following code snip.

...
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;
... 
try 
{
   Debug.WriteLine("Looking for: " + DisplayName);
   DirectoryEntry entry = new DirectoryEntry(strLDAP, strUserName, strPassword);
   DirectorySearcher Searcher = new DirectorySearcher(entry);
   Searcher.Filter = "(displayName="+ DisplayName +")";
   SearchResult result = Searcher.FindOne();     
   DirectoryEntry found = result.GetDirectoryEntry();

   // tell if we found the right user
   Debug.WriteLine(found.Properties["mail"][0].ToString());

   // tell what the current terminal services profile path is
   Debug.WriteLine(found.InvokeGet("TerminalServicesProfilePath").ToString()); 
}
catch (DirectoryServicesComException e)
{
  Debug.WriteLine(e.Message.ToString());
}

Sadly I get the following error when I do an InvokeGet:

... System.Runtime.InteropServices.COMException' occurred in System.DirectoryServices.dll System.Runtime.InteropServices.COMException (0x80020006): Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))

I'm bumped here.. I know the parameter TerminalServicesProfilePath is in AD in a "userParameter" hash. And invoking it should get something readable.

What am I doing wrong?

Side note: the AD resides on a 2003 level domain.

c#
active-directory
asked on Stack Overflow Jan 29, 2013 by DeChinees • edited Jan 29, 2013 by istepaniuk

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0