我正在尝试为指定OU中的每个AD用户修改配置文件/主目录/主驱动器设置,
我下面有一些非常基本的代码应该可以实现这一壮举,但是却抛出以下异常:
请求的操作不满足与该对象的类别相关联的一个或多个约束。
有没有人遇到过这个问题,如果有,有办法解决吗?
谢谢。
DirectoryEntry Entry = new DirectoryEntry("LDAP://OU=Company,DC=corp,DC=Placeholder,DC=com", null, null, AuthenticationTypes.Secure);
DirectorySearcher Searcher = new DirectorySearcher(Entry);
Searcher.SearchScope = SearchScope.Subtree;
Searcher.PropertiesToLoad.Add("sAMAccountName");
Searcher.Filter = "(&(objectClass=user)(objectCategory=person))";
foreach (SearchResult AdObj in Searcher.FindAll())
{
Entry.InvokeSet("HomeDirectory", @"\\winfileserver\" + Convert.ToString(AdObj.Properties["sAMAccountName"][0]));
Entry.InvokeSet("HomeDrive", "H");
Entry.CommitChanges();
}
catch (Exception ex)
{
richTextBox1.Text += ex.Message;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下内容,无法解决为什么这个IndexOf方法不起作用的问题。
foreach (string s in regKey.GetSubKeyNames())
{
RegistryKey sub = Registry.LocalMachine.OpenSubKey(string.Format(@"{0}\{1}", _UninstallKey64Bit, s), false);
if (sub.ValueCount > 0)
{
values = sub.GetValueNames();
if (IndexOf(values, "DisplayName") != -1)
{
string name = (sub.GetValue("DisplayName") != null) ? sub.GetValue("DisplayName").ToString() : string.Empty;
if (!string.IsNullOrEmpty(name) && (name.ToLower() == appName.ToLower()))
if (IndexOf(values, "UninstallString") != -1)
{
uninstallValue = (sub.GetValue("UninstallString") != null) ? sub.GetValue("UninstallString").ToString() : string.Empty;
break;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我吗?