如何以编程方式访问远程桌面服务用户配置文件路径?

How do i access the remote desktop services user profile path programatically?

因此,其中有一些帖子有点 "older",但我刚刚遇到这个,无法获得这些属性。

基本上我需要的是能够访问 Active Directory 中的 "Remote Desktop Services User Profile Path"。我已经在网上尝试了几件事,包括用于 powershell 的 ADSI,但是 "TerminalServicesHomeDirectory" attritube 或 属性 无论你想怎么称呼它,它都没有返回。我还尝试了以下应该能够设置它的代码。这也不起作用。

        PrincipalContext PC = new PrincipalContext(ContextType.Domain);
        UserPrincipal UP = UserPrincipal.FindByIdentity(PC, "testact");
        DirectoryEntry DE = (DirectoryEntry)UP.GetUnderlyingObject();
        DE.InvokeSet("TerminalServicesHomeDirectory", new object[] { "testing" });
        DE.CommitChanges();

我知道我在某处读到过您应该使用 "tsuserex.dll" 但是我没有成功将其添加为参考。我在我的机器上发现了其中两个,一个列在 system32 中,一个列在 "c:\Windows\WinSxS\amd64......." 中,但它们都没有加载。他们只是产生一个错误

"a reference to $pathhere\tsuserex.dll could not be added. please make sure
the file is accessible, and that it is a valid assembly or COM component."

我已经在互联网上搜索了很多,所以现在我希望所有强大的 SO 能来拯救我。顺便说一下,我在 64 位 windows 10 机器上。

原来我的解决方案一直都是正确的,我猜只是花了一点时间来更新。

    PrincipalContext PC = new PrincipalContext(ContextType.Domain);
    UserPrincipal UP = UserPrincipal.FindByIdentity(PC, "testact");
    DirectoryEntry DE = (DirectoryEntry)UP.GetUnderlyingObject();
    //To Change the value
    DE.InvokeSet("TerminalServicesHomeDirectory", new object[] { "testing" });
    DE.CommitChanges();
    //to get the value
    string value = DE.InvokeGet("TerminalServicesHomeDirectory");

这是获取或更改这些值所需的全部代码。您也可以使用 TerminalServicesProfilePath 属性.