2011-10-19 6 views
3

네트워크에있는 모든 PC를 쿼리하여 실제로 로그온 한 사용자를 확인하는 방법. "IPAddress + LogedUserName"목록을 가져와야합니다.C# 네트워크에 로그온 한 사용자 확인

나는이 방법으로 LAN에서 사용할 수있는 컴퓨터의 목록을 얻고있다 :

using (DirectoryEntry root = new DirectoryEntry("WinNT:")) 
     { 
      foreach (DirectoryEntry computers in root.Children) 
      { 
       foreach (DirectoryEntry computer in computers.Children) 
       { 
        if ((computer.Name != "Schema")) 
        { 
         textBox1.Text += computer.Name + "\r\n"; 
        } 
       } 
      } 
     } 

을하지만 또한 사용 가능한 각 컴퓨터에 로그온 한 사용자의 이름을 갖고 싶어.

+0

도메인에 있습니까? 더 많은 세부 사항을 제공해야합니다. 그렇기 때문에 문제는 종결 될 가능성이 큽니다. –

+0

질문을 수정 했습니까? 나는 컴퓨터의 가용성에 IP 주소의 범위를 확인하고, 그 이름을 얻고 현재 로그인 된 사용자 명을 얻고 싶다. – DefinitionHigh

+0

훨씬 더 좋았고, 나는 재개하기로 결정했다. –

답변

1

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; 
      } 
     } 
    } 
} 
+0

안녕하세요 Scott Chamberlain, 저는 같은 질문을 가지고 있습니다. 귀하의 답변이 내 솔루션이라고 생각하여 귀하의 코드를 시도했지만 어떤 것도 반환하지 않습니다! 너는 어떤 제안이 없니? 이 코드가 서버에서 실행되어야합니까? –

+0

나는 당신이 한 일과 그 과정에서 얻은 모든 오류 메시지를 정확하게 보여주는 새로운 질문을 열 것입니다. 어떤 버전의 .NET과 프로그램을 실행중인 OS가 포함되어 있는지 확인하십시오. –

+0

나는 내 질문에 이미 http://stackoverflow.com/questions/14302861/getting-a-list-of-every-active-computers-on-the-network를 요청했지만 아직 아무도 대답하지 못했다. –

관련 문제