Question

I have read the following properties from AD,

TerminalServicesProfilePath
TerminalServicesHomeDirectory
TerminalServicesHomeDrive

I've tried DirectoryEntry and DirectorySearcher. But they does not include the properties.

I found some example in vbscript and VC to read them. However I failed to make it working in C#. Am I missing some tricky thing?

EDIT: Am I have to run it on "Windows Server" to make it works? Can it be read from win XP?

Was it helpful?

Solution

I don't remember exactly, but it's something like this:

//user is a DirectoryEntry
IADsTSUserEx adsiUser = (IADsTSUserEx)user.NativeObject; 

then you can get the TerminalServices properties you want via adsiUser.

From my experience you're better off developing on a Windows Server with access to AD due to the libraries you use. Then you'll probably make the above work, too :)

OTHER TIPS

I think you can use the InvokeGet method on your DirectoryEntry, passing in the name of the property you want to read.

2008-12-10 11:50 CET — Edited in response to the comment

If I specify a garbage property name, I get the same COM exception. Are you sure the properties you're trying to retrieve are part of the AD schema?

Just to make sure, the code I'm using is as follows:

using (DirectorySearcher searcher = new DirectorySearcher("(cn=Test)"))
{
    SearchResult result = searcher.FindOne();
    if (result != null)
    {
        DirectoryEntry entry = result.GetDirectoryEntry();
        string s = entry.InvokeGet("TerminalServicesHomeDrive") as string;
        MessageBox.Show(s ?? "null");
    }
}

This works for me:

            DirectoryEntry user = new DirectoryEntry("LDAP://" + sLDAP_SERVER + "/cn=" + SAMAccount + "," + sLdapFullPath, sUser, sPwd);

            //ActiveDs.IADsUser iADsUser = (ActiveDs.IADsUser)user.NativeObject;
            ActiveDs.IADsUser cont = null;

            cont = user.NativeObject as ActiveDs.IADsUser;

            TSUSEREXLib.IADsTSUserEx m_TsUser = (TSUSEREXLib.IADsTSUserEx)cont;
            int m_TSLogonDisabled = 0;

            m_TsUser.AllowLogon = m_TSLogonDisabled;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top