C# 使用C更改AD用户终端服务器属性#
我正在使用System.DirectoryServices.DirectoryEntry创建AD用户,除某些远程桌面特定属性外,其他一切都正常工作 例如:C# 使用C更改AD用户终端服务器属性#,c#,properties,directoryentry,C#,Properties,Directoryentry,我正在使用System.DirectoryServices.DirectoryEntry创建AD用户,除某些远程桌面特定属性外,其他一切都正常工作 例如: newUser.Properties["msTSConnectClientDrives"].Value = false; newUser.Properties["msTSConnectPrinterDrives"].Value = false; newUser.Properties["msTSDefaultToMainPrinter"].Va
newUser.Properties["msTSConnectClientDrives"].Value = false;
newUser.Properties["msTSConnectPrinterDrives"].Value = false;
newUser.Properties["msTSDefaultToMainPrinter"].Value = false;
这不会引发任何异常,因此我猜属性可以在对象中找到,但它们没有任何效果。当我进入该用户的属性窗口,在“环境”选项卡下,这3个复选框仍然处于选中状态
我是否遗漏了这些属性的某些特定内容
谢谢你的帮助
编辑:
抱歉,我一直很忙,下面是一个代码示例:
private string CreateNewADAccount(string accountName, string accountPassword)
{
try
{
PrincipalContext context = new PrincipalContext(ContextType.Domain, "SV-LITE", @"LITE\xxxxxxxx", "yyyyyyyy");
UserPrincipal newUser = new UserPrincipal(context);
newUser.SamAccountName = accountName;
newUser.UserPrincipalName = accountName;
newUser.Name = "LiteUser2015 - " + accountName;
newUser.DisplayName = "LiteUser2015 - " + accountName;
newUser.SetPassword(accountPassword);
newUser.PasswordNeverExpires = true;
newUser.UserCannotChangePassword = true;
newUser.Save();
// Set advanced properties
if (newUser.GetUnderlyingObjectType() == typeof(DirectoryEntry))
{
DirectoryEntry entry = (DirectoryEntry)newUser.GetUnderlyingObject();
entry.Properties["msTSConnectClientDrives"].Value = false;
entry.Properties["msTSConnectPrinterDrives"].Value = false;
entry.Properties["msTSDefaultToMainPrinter"].Value = false;
entry.Properties["msTSInitialProgram"].Value = "test";
entry.CommitChanges();
}
return newUser.Guid.ToString();
}
catch (Exception e)
{
MessageBox.Show("Failed to create PrincipalContext. Exception: " + e);
}
return null;
}
进行更改后,必须调用CommitChanges-
newUser.CommitChanges()代码>
看
默认情况下,对属性的更改在本地缓存中进行
这可能与您正在使用的服务器操作系统版本有关。我在一篇关于Windows 2000和2003的文章中找到了这个答案。它应适用于Windows 2008及更高版本:
对于2000/2003,您必须使用终端服务访问它们
ADSI扩展。参考资料如下:
好的(我可能应该在评论中询问)。不管怎样,这里有一篇MSDN文章说Windows 2008及以上版本确实支持它:您能用更完整的代码示例更新您的问题吗?