0
我試圖recive在我的廣告中的所有計算機,以及他們當中哪些whos當前登錄。我試着通過檢查「lastLogonStamp」但是返回錯誤的值,說我的服務器在八天前登錄到了AD。即使我重啓服務器,它也是如此。我從另一個問題在這裏代碼:獲取所有計算機的列表,並且如果它登錄到AD
How to list all computers and the last time they were logged onto in AD?
public DataTable GetListOfComputers(string domain, string userName, string password)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain,
userName, password, AuthenticationTypes.Secure);
DirectorySearcher search = new DirectorySearcher(entry);
string query = "(objectclass=computer)";
search.Filter = query;
search.PropertiesToLoad.Add("name");
search.PropertiesToLoad.Add("lastLogonTimestamp");
SearchResultCollection mySearchResultColl = search.FindAll();
DataTable results = new DataTable();
results.Columns.Add("name");
results.Columns.Add("lastLogonTimestamp");
foreach (SearchResult sr in mySearchResultColl)
{
DataRow dr = results.NewRow();
DirectoryEntry de = sr.GetDirectoryEntry();
dr["name"] = de.Properties["Name"].Value;
dr["lastLogonTimestamp"] = DateTime.FromFileTimeUtc(long.Parse(sr.Properties["lastLogonTimestamp"][0].ToString()));
results.Rows.Add(dr);
de.Close();
}
return results;
}
感謝您的快速響應! 我在哪裏通過憑據?在我的例子中,我將IP地址傳遞給AD服務器,「管理員」,「密碼」。我如何驗證自己? PS:我的網絡服務器不在AD中。我只是連接到它外部。 DS。 –