代码之家  ›  专栏  ›  技术社区  ›  Dennis C

如何在C#中从LDAP读取TermainsServices IADsTSUserEx属性?

  •  2
  • Dennis C  · 技术社区  · 17 年前

    TerminalServicesProfilePath
    TerminalServicesHomeDirectory
    TerminalServicesHomeDrive
    

    我试过DirectoryEntry和DirectorySearcher。但它们不包括属性。

    我在vbscript和VC中找到了一些示例来阅读它们。

    编辑:我必须在“Windows服务器”上运行它才能使其正常工作吗?它可以从win XP中读取吗?

    3 回复  |  直到 17 年前
        1
  •  3
  •   Arnout    17 年前

    我想你可以用 InvokeGet 你的方法 DirectoryEntry

    2008-12-10 11:50 CET-根据评论编辑

    为了确保这一点,我使用的代码如下:

    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");
        }
    }
    
        2
  •  1
  •   chriscena    17 年前

    我记不清了,但大致是这样的:

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

    然后,您可以通过adsiUser获得所需的TerminalServices属性。

        3
  •  1
  •   user186497 user186497    16 年前

    这对我很有用:

                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;
    
    推荐文章