我需要读/写 ActiveDirectory 用户对象终端服务属性。我试过这个:
PrincipalContext context = new PrincipalContext(ContextType.Domain, "CA");
using (context)
{
UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "CA\\vlekovic");
if (user != null)
{
DirectoryEntry entry = (DirectoryEntry)user.GetUnderlyingObject();
entry.Properties["msTSProfilePath"].Value = "";
entry.Properties["msTSHomeDirectory"].Value = "";
entry.Properties["msTSHomeDrive"].Value = "";
entry.CommitChanges();
}
}
我试过这个:
PrincipalContext context = new PrincipalContext(ContextType.Domain, "CA");
using (context)
{
UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "CA\\vlekovic");
if (user != null)
{
DirectoryEntry entry = (DirectoryEntry)user.GetUnderlyingObject();
entry.InvokeSet("msTSProfilePath", "");
entry.InvokeSet("msTSHomeDirectory", "");
entry.InvokeSet("msTSHomeDrive", "");
entry.CommitChanges();
}
}
但没有任何效果。
我还尝试了以下属性名称:
- 终端服务配置文件路径
- 终端服务首页目录
- 终端服务HomeDrive
但没有运气。任何帮助,将不胜感激!
谢谢, 沃金