成人AV在线无码|婷婷五月激情色,|伊人加勒比二三四区|国产一区激情都市|亚洲AV无码电影|日av韩av无码|天堂在线亚洲Av|无码一区二区影院|成人无码毛片AV|超碰在线看中文字幕

C#獲取域用戶列表

private string RunCmd(string command){//實例一個Process 類,啟動一個獨立進程Process p = new Process();//Process類有一

private string RunCmd(string command)

{

//實例一個Process 類,啟動一個獨立進程

Process p = new Process();

//Process類有一個StartInfo 屬性,這個是ProcessStartInfo 類,包括了一些屬性和方法,下面我們用到了他的幾個屬性:

p.StartInfo.FileName = "cmd.exe"; //設(shè)定程序名

p.StartInfo.Arguments = "/c " command; //設(shè)定程式執(zhí)行參數(shù) p.StartInfo.UseShellExecute = false; //關(guān)閉Shell 的使用 p.StartInfo.RedirectStandardInput = true; //重定向標(biāo)準(zhǔn)輸入 p.StartInfo.RedirectStandardOutput = true; //重定向標(biāo)準(zhǔn)輸出 p.StartInfo.RedirectStandardError = true; //重定向錯誤輸出 p.StartInfo.CreateNoWindow = true; //設(shè)置不顯示窗口

p.Start(); //啟動

//p.StandardInput.WriteLine(command); //也可以用這種方式輸入要執(zhí)行的命令

//p.StandardInput.WriteLine("exit"); //不過要記得加上Exit 要不然下一行程式執(zhí)行的時候會當(dāng)機

return p.StandardOutput.ReadToEnd(); //從輸出流取得命令執(zhí)行結(jié)果

}

private static SearchResultCollection _ADHelper(string domainADsPath, string username, string password, string schemaClassNameToSearch)

{

DirectorySearcher searcher = new DirectorySearcher();

searcher.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 paged search

searcher.PageSize = 512;

searcher.PropertiesToLoad.AddRange(new string[] { "name", "Path", "displayname", "samaccountname", "mail" });

,

SearchResultCollection results = searcher.FindAll();

return results;

//參數(shù)domainADsPath 是活動目錄的域名,使用類似"LDAP://域名" 的形式

//參數(shù)schemaClassNameToSearch 是過濾條件,

// objectClass=user 查詢條件是所有的用戶(USER )

}

public GetUserList()

{ }

public string [] ListUsers()

{

string path = "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:數(shù)據(jù)對象 指定要獲取的內(nèi)容

return ListUsers(path);

}

public string[] ListUsers(string path)

{

try

{

DirectoryEntry entry = new DirectoryEntry(path);

DirectorySearcher searcher = new DirectorySearcher(entry); searcher.Filter = "(objectClass=*)";

searcher.PropertiesToLoad.Clear();

SearchResultCollection searchResultCollection = searcher.FindAll();

return VisitSearchResultCollection(searchResultCollection); }

catch (Exception ex) { log.Debug(ex.Message); return 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("samaccountname"))

{

ResultPropertyValueCollection resultValue

result.Properties["samaccountname"];

if(resultValue!= null && resultValue.Count

resultValue[0] != null )

{

userName = resultValue[0].ToString();

}

}

if (result.Properties.Contains("displayname"))

{

ResultPropertyValueCollection resultValue

result.Properties["displayname"];

if(resultValue!= null && resultValue.Count

resultValue[0] != null )

{

displayName = resultValue[0].ToString();

}

}

userList.Add(new Users(userName,displayName));

}

UploadHHTHistory(userList);

}

= >0 && = >0 &&

標(biāo)簽: