2011-10-19 7 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

こんにちはスコットチェンバレン、私は同じ質問があると私はあなたの答えは私のソリューションだと思ったので、私はあなたのコードを試したが、それは何も戻っていない!何か提案はありませんか?このコードをサーバー上で実行する必要がありますか? –

+0

私はあなたがしたことを正確に示している新しい質問を開き、あなたがそのプロセスで得たエラーメッセージを表示します。 .NETのバージョンと、あなたのプログラムを実行しているOSが含まれていることを確認してください。 –

+0

私は既に私の質問をhttp://stackoverflow.com/questions/14302861/getting-a-list-of-every-active-computers-on-the-networkに依頼しましたが、誰も回答しませんでした。 –

関連する問題