現在您的問題已重新打開,這裏是使用cassia的更完整解釋。這可能會或可能不會在沒有啓用RemoteDesktop的桌面上運行。這段代碼完全沒有經過測試,它可能需要一些修補程序才能100%工作,但它會讓你走上正軌。
using (DirectoryEntry root = new DirectoryEntry("WinNT:"))
{
ITerminalServicesManager tsm = new Cassia.TerminalServicesManager();
foreach (DirectoryEntry computers in root.Children)
foreach (DirectoryEntry computer in computers.Children)
{
if ((computer.Name != "Schema"))
{
string linqCapture = computer.Name; //<-- This may not be necessary,
//but I have always have had bad
//experiences with LINQ and foreach
//loops not capturing the current
//value of the variable correctly.
//remove the last Where clause if you want all users connected
//to the computer, not just the one where it is the console session.
foreach(var session in tsm.GetSessions(linqCapture)
.Where(s => s.ConnectionState == ConnectionState.Active)
.Where(s => s.ClientName == linqCapture))
{
string LoggedInUser = session.UserName;
System.Net.IPAddress LoggedInIp = session.ClientIPAddress;
//Do with data what ever you want to;
}
}
}
}
您是否是域名?你需要提供更多的細節,因爲這個問題很可能會被關閉。 –
編輯了這個問題,好嗎?我想檢查IP地址範圍到電腦的可用性,得到它的名字,並獲得當前loged用戶名.. – DefinitionHigh
好多了,我投票重新打開。 –