C#获取域用户列表

C#获取域用户列表

ID:38978744

大小:28.00 KB

页数:3页

时间:2019-06-22

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

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

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

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

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

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

5、hsearcher.PageSize=512;searcher.PropertiesToLoad.AddRange(newstring[]{"name","Path","displayname","samaccountname","mail"});SearchResultCollectionresults=searcher.FindAll();returnresults;//参数domainADsPath是活动目录的域名,使用类似"LDAP://域名"的形式//参数schemaClassNameToSearch是过滤条件,//objectClass=

6、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);}publicstring[]ListUsers(stringpath){try{DirectoryE

7、ntryentry=newDirectoryEntry(path);DirectorySearchersearcher=newDirectorySearcher(entry);searcher.Filter="(objectClass=*)";searcher.PropertiesToLoad.Clear();SearchResultCollectionsearchResultCollection=searcher.FindAll();returnVisitSearchResultCollection(searchResultCollection);

8、}catch(Exceptionex){log.Debug(ex.Message);returnnewstr

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

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

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