C#獲取域用戶(hù)列表_第1頁(yè)
C#獲取域用戶(hù)列表_第2頁(yè)
C#獲取域用戶(hù)列表_第3頁(yè)
C#獲取域用戶(hù)列表_第4頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、-作者xxxx-日期xxxxC#獲取域用戶(hù)列表【精品文檔】private string RunCmd(string command) /實(shí)例一個(gè)Process類(lèi),啟動(dòng)一個(gè)獨(dú)立進(jìn)程 Process p = new Process(); /Process類(lèi)有一個(gè)StartInfo屬性,這個(gè)是ProcessStartInfo類(lèi),包括了一些屬性和方法,下面我們用到了他的幾個(gè)屬性: p.StartInfo.FileName = cmd.exe; /設(shè)定程序名 p.StartInfo.Arguments = /c + command; /設(shè)定程式執(zhí)行參數(shù) p.StartInfo.UseShellExecu

2、te = false; /關(guān)閉Shell的使用 p.StartInfo.RedirectStandardInput = true; /重定向標(biāo)準(zhǔn)輸入 p.StartInfo.RedirectStandardOutput = true; /重定向標(biāo)準(zhǔn)輸出 p.StartInfo.RedirectStandardError = true; /重定向錯(cuò)誤輸出 p.StartInfo.CreateNoWindow = true; /設(shè)置不顯示窗口 p.Start(); /啟動(dòng) /p.StandardInput.WriteLine(command); /也可以用這種方式輸入要執(zhí)行的命令 /p.Stand

3、ardInput.WriteLine(exit); /不過(guò)要記得加上Exit要不然下一行程式執(zhí)行的時(shí)候會(huì)當(dāng)機(jī) return p.StandardOutput.ReadToEnd(); /從輸出流取得命令執(zhí)行結(jié)果private static SearchResultCollection _ADHelper(string domainADsPath, string username, string password, string schemaClassNameToSearch) DirectorySearcher searcher = new DirectorySearcher(); searc

4、her.SearchRoot = new DirectoryEntry(domainADsPath,username, password); searcher.Filter = (objectClass= + schemaClassNameToSearch + ); searcher.SearchScope = SearchScope.Subtree; searcher.Sort = new SortOption(name,SortDirection.Ascending); / If there is a large set to be return ser page size for a p

5、aged search searcher.PageSize = 512;opertiesToLoad.AddRange(new string name, Path, displayname, samaccountname, mail ); SearchResultCollection results = searcher.FindAll(); return results;/參數(shù)domainADsPath是活動(dòng)目錄的域名,使用類(lèi)似LDAP:/域名的形式/參數(shù)schemaClassNameToSearch是過(guò)濾條件,/ objectClass=user 查詢(xún)條件是所有的用戶(hù)(USER) publ

6、ic GetUserList() public string ListUsers() string path = LDAP:/IP/CN=Users,DC=idm,DC=gad,DC=nec,DC=com,DC=cn; / IP:ADIP地址 / DC:域例如 ,cn 可以寫(xiě)為 DC=sina,DC=com,DC=cn / CN:數(shù)據(jù)對(duì)象 指定要獲取的內(nèi)容 return ListUsers(path); public string ListUsers(string path) try DirectoryEntry entry = new DirectoryEntry(path); Direct

7、orySearcher searcher = new DirectorySearcher(entry); searcher.Filter = (objectClass=*); searcher.PropertiesToLoad.Clear(); SearchResultCollection searchResultCollection = searcher.FindAll(); return VisitSearchResultCollection(searchResultCollection); catch (Exception ex) log.Debug(ex.Message); retur

8、n new string 0; /string messageFormat = key:0 value:1 desc:; public void VisitSearchResultCollection(SearchResultCollection resultCollection) IList userList = new List(); foreach(SearchResult result in resultCollection) string userName; string displayName; if (result.Properties.Contains(samaccountna

9、me) ResultPropertyValueCollection resultValue = result.Propertiessamaccountname; if(resultValue!= null & resultValue.Count 0 & resultValue0 != null ) userName = resultValue0.ToString(); if (result.Properties.Contains(displayname) ResultPropertyValueCollection resultValue = result.Propertiesdisplayname; if(resultValue!= null & resultValue.Count 0

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論