ActiveDirectory本地计算机帐户管理-C#
我发布了一个关于LDAP帐户管理的问题,但在探讨了这个问题之后,我并不想问这个问题。我已经找到了两种在机器上创建用户的方法,我发现其中一种比另一种更简洁,但是,我不确定如何将第一个选项完全转换为第二个选项 这是我的第一个解决方案:ActiveDirectory本地计算机帐户管理-C#,c#,.net,active-directory,C#,.net,Active Directory,我发布了一个关于LDAP帐户管理的问题,但在探讨了这个问题之后,我并不想问这个问题。我已经找到了两种在机器上创建用户的方法,我发现其中一种比另一种更简洁,但是,我不确定如何将第一个选项完全转换为第二个选项 这是我的第一个解决方案: Process MyProc = new Process(); MyProc.StartInfo.WorkingDirectory = System.Environment.SystemDirectory; MyProc
Process MyProc = new Process();
MyProc.StartInfo.WorkingDirectory = System.Environment.SystemDirectory;
MyProc.StartInfo.FileName = "net.exe";
MyProc.StartInfo.UseShellExecute = false;
MyProc.StartInfo.RedirectStandardError = true;
MyProc.StartInfo.RedirectStandardInput = true;
MyProc.StartInfo.RedirectStandardOutput = true;
MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
MyProc.StartInfo.Arguments = string.Format(@" user {0} {1} /ADD /ACTIVE:YES /EXPIRES:NEVER /FULLNAME:{0}"" /PASSWORDCHG:NO /PASSWORDREQ:YES", username, password);
MyProc.Start();
MyProc.WaitForExit();
int exit = MyProc.ExitCode;
MyProc.Close();
return exit == 0;
DirectoryEntry root = GetDELocalRoot();
DirectoryEntry user = root.Children.Add(username, "user");
//TODO: Always Active
//TODO: Never Expires
//TODO: No Password Change
//TODO: Password Required
user.Properties["description"].Value = "Account for running the MicaService and handling updates.";
user.Invoke("SetPassword", new object[] { password });
user.CommitChanges();
user.Close();
这是我的第二个(首选)解决方案:
Process MyProc = new Process();
MyProc.StartInfo.WorkingDirectory = System.Environment.SystemDirectory;
MyProc.StartInfo.FileName = "net.exe";
MyProc.StartInfo.UseShellExecute = false;
MyProc.StartInfo.RedirectStandardError = true;
MyProc.StartInfo.RedirectStandardInput = true;
MyProc.StartInfo.RedirectStandardOutput = true;
MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
MyProc.StartInfo.Arguments = string.Format(@" user {0} {1} /ADD /ACTIVE:YES /EXPIRES:NEVER /FULLNAME:{0}"" /PASSWORDCHG:NO /PASSWORDREQ:YES", username, password);
MyProc.Start();
MyProc.WaitForExit();
int exit = MyProc.ExitCode;
MyProc.Close();
return exit == 0;
DirectoryEntry root = GetDELocalRoot();
DirectoryEntry user = root.Children.Add(username, "user");
//TODO: Always Active
//TODO: Never Expires
//TODO: No Password Change
//TODO: Password Required
user.Properties["description"].Value = "Account for running the MicaService and handling updates.";
user.Invoke("SetPassword", new object[] { password });
user.CommitChanges();
user.Close();
我想将我的TODO:中的所有设置从第一个解决方案映射到第二个更整洁的解决方案
我也试过下面这句话:
user.Properties["userAccountControl"].Value = ADS_USER_FLAG.ADS_UF_NORMAL_ACCOUNT | ADS_USER_FLAG.ADS_UF_PASSWD_CANT_CHANGE | ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD;
但这不起作用,因为缓存中不存在该属性
注意:GetDELocalRoot()返回新的DirectoryEntry(“WinNT://”+Environment.MachineName)
谢谢你的意见
问候
Tris看看我的朋友,他有很多有用的信息和参考资料,说明这两个提供商(WinNT用于本地机器帐户,而LDAP用于网络帐户)必须提供什么
WinNT提供程序还公开了一个新的属性,它比LDAP提供程序所公开的要少得多,因此我不确定您是否能够设置所有要查找的属性
Marc看看我的朋友,他有很多有用的信息和参考资料,说明这两个提供商——WinNT用于本地机器帐户,而LDAP用于网络帐户——必须提供什么
WinNT提供程序还公开了一个新的属性,它比LDAP提供程序所公开的要少得多,因此我不确定您是否能够设置所有要查找的属性
马克