



下載本文檔
版權(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 人力資源的研究報(bào)告范文
- 請(qǐng)示性申請(qǐng)報(bào)告范文
- 浙江國(guó)企招聘2024金華義烏市城投工程咨詢(xún)有限公司招聘4人筆試參考題庫(kù)附帶答案詳解
- 浙江國(guó)企招聘2024浙江杭州女子足球俱樂(lè)部有限公司招聘2人筆試參考題庫(kù)附帶答案詳解
- 黨支部聯(lián)建建協(xié)議書(shū)(2025)脫貧攻堅(jiān)共建合作協(xié)議
- 個(gè)人商鋪?zhàn)赓U合同協(xié)議書(shū)(2025年度)
- 二零二五年度寵物食品電商平臺(tái)商家入駐合作協(xié)議
- 二零二五年度插畫(huà)與音樂(lè)制作合作約稿合同
- 二零二五年度中式快餐連鎖區(qū)域代理授權(quán)書(shū)
- 2025年度綠色能源產(chǎn)品銷(xiāo)售及安裝服務(wù)合同
- 重慶市南開(kāi)名校2024-2025學(xué)年八年級(jí)下學(xué)期開(kāi)學(xué)考試物理試題(含答案)
- 2025年湖南生物機(jī)電職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)傾向性測(cè)試題庫(kù)1套
- 滲漉法胡鵬講解
- 2025年交管12123學(xué)法減分試題庫(kù)附參考答案
- 《大模型原理與技術(shù)》全套教學(xué)課件
- 2024年中鐵集裝箱運(yùn)輸有限責(zé)任公司招聘筆試參考題庫(kù)附帶答案詳解
- 陳情表原文及翻譯
- 品茗安全計(jì)算軟件新手入門(mén)教程1梁模板扣件式
- 預(yù)應(yīng)力空心板吊裝專(zhuān)項(xiàng)施工方案
- 印刷生產(chǎn)日?qǐng)?bào)表
- 鞍鋼鲅魚(yú)圈鋼鐵項(xiàng)目38m生產(chǎn)線工程設(shè)計(jì)思想
評(píng)論
0/150
提交評(píng)論