我想使用.NET代码从Windows读取,添加和删除用户。 我怎样才能做到这一点?
C#:从文件打印图像
win32 api是否过时了?
在标准C ++或C#上使用C ++ / CLI有什么好处吗?
创build可通过在背景区域中的任意位置拖动来移动的非矩形窗体
ASP.NET和不完整的HTTP请求
public static bool CreateLocalWindowsAccount(string username,string password,string displayName,string description,bool canChangePwd,bool pwdExpires) { try { PrincipalContext context = new PrincipalContext(ContextType.Machine); UserPrincipal user = new UserPrincipal(context); user.SetPassword(password); user.displayName = displayName; user.Name = username; user.Description = description; user.UserCannotChangePassword = canChangePwd; user.PasswordNeverExpires = pwdExpires; user.Save(); //Now add user to "Users" group so it displays in Control Panel GroupPrincipal group = GroupPrincipal.FindByIdentity(context,"Users"); group.Members.Add(user); group.Save(); return true; } catch (Exception ex) { MessageBox.Show("Error creating account: {0}",ex.Message); return false; } }
添加一个对System.DirectoryServices的引用可以让你阅读所有的Windows用户做这样的事情:
DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName); DirectoryEntry admGroup = localMachine.Children.Find("administrators","group"); object members = admGroup.Invoke("members",null); foreach (object groupMember in (IEnumerable)members) { DirectoryEntry member = new DirectoryEntry(groupMember); lstUsers.Items.Add(member.Name); }
一般而言, DirectoryServices命名空间应允许您导航并阅读Active Directory
您将需要使用ActiveDirectory和DirectoryEntry
Imports System.DirectoryServices.ActiveDirectory Imports System.Collections.DictionaryEntry
LDAP是我认为WinNT一个选项。
你可以用WinNT访问目录://像这样
Dim de As New System.DirectoryServices.DirectoryEntry() Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs Handles Button1.Click de.Path = "WinNT://*****".Replace("*****",ActiveDirectory.DomainGetCurrentDomain.Name)
与用户合作
另外我还有几个问题涉及ActiveDirectory使用一个月前(所以我不记得深入)。 也许从我的个人资料中的一些东西可以帮助你。 祝你好运
除了绝对有效的其他答案,我们也使用LINQ到AD …
http://linqtoad.codeplex.com/
…在一些可以简单查询的项目上很容易。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。