C#获取域用户列表.doc

C#获取域用户列表.doc

ID:60749236

大小:25.50 KB

页数:4页

时间:2020-12-13

C#获取域用户列表.doc_第1页
C#获取域用户列表.doc_第2页
C#获取域用户列表.doc_第3页
C#获取域用户列表.doc_第4页
资源描述:

《C#获取域用户列表.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、__________________________________________________privatestringRunCmd(stringcommand){//實例一個Process類,啟動一個獨立進程Processp=newProcess();//Process類有一個StartInfo屬性,這個是ProcessStartInfo類,包括了一些屬性和方法,下面我們用到了他的幾個屬性:p.StartInfo.FileName="cmd.exe";//設定程序名p.StartInfo.Arguments="/c"+command;//設定程式執行參數p.Start

2、Info.UseShellExecute=false;//關閉Shell的使用p.StartInfo.RedirectStandardInput=true;//重定向標準輸入p.StartInfo.RedirectStandardOutput=true;//重定向標準輸出p.StartInfo.RedirectStandardError=true;//重定向錯誤輸出p.StartInfo.CreateNoWindow=true;//設置不顯示窗口p.Start();//啟動//p.StandardInput.WriteLine(command);//也可以用這種方式輸入要執行

3、的命令//p.StandardInput.WriteLine("exit");//不過要記得加上Exit要不然下一行程式執行的時候會當機returnp.StandardOutput.ReadToEnd();//從輸出流取得命令執行結果}privatestaticSearchResultCollection_ADHelper(stringdomainADsPath,stringusername,stringpassword,stringschemaClassNameToSearch){DirectorySearchersearcher=newDirectorySearcher(

4、);searcher.SearchRoot=newDirectoryEntry(domainADsPath,username,password);searcher.Filter="(objectClass="+schemaClassNameToSearch+")";searcher.SearchScope=SearchScope.Subtree;searcher.Sort=newSortOption("name",SortDirection.Ascending);//Ifthereisalargesettobereturnserpagesizeforapagedsearchs

5、earcher.PageSize=512;searcher.PropertiesToLoad.AddRange(newstring[]{"name","Path","displayname","samaccountname","mail"});收集于网络,如有侵权请联系管理员删除__________________________________________________SearchResultCollectionresults=searcher.FindAll();returnresults;//参数domainADsPath是活动目录的域名,使用类似"LDAP://

6、域名"的形式//参数schemaClassNameToSearch是过滤条件,//objectClass=user查询条件是所有的用户(USER)}publicGetUserList(){}publicstring[]ListUsers(){stringpath="LDAP://IP/CN=Users,DC=idm,DC=gad,DC=nec,DC=com,DC=cn";//IP:ADIP地址//DC:域例如sina.com,cn可以写为DC=sina,DC=com,DC=cn//CN:数据对象指定要获取的内容returnListUsers(path);}publicstri

7、ng[]ListUsers(stringpath){try{DirectoryEntryentry=newDirectoryEntry(path);DirectorySearchersearcher=newDirectorySearcher(entry);searcher.Filter="(objectClass=*)";searcher.PropertiesToLoad.Clear();SearchResultCollectionsearchResultCollection=searcher.Find

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。