Get the name of the computer where a user is logged in

2

We have a system that seeks and obtains the information of all the workers of an active directory, we want to know how we can do it to know that TEAM within the company network is using at that moment worker when we look for it, for example:

I look for the employee 1111 and inside the information that already shows me also show me the name of the team in which this is logged because in active directory we do not see any field that says it as such, as for example if do the givenName , or the sn that return our first and last name.

We appreciate any help or suggestion that you can give us

    
asked by sullivan96 25.01.2018 в 21:14
source

1 answer

-1

You should have a connection to the active directory to do it and get the information there is a generic code you just have to put the connection data that would be the user and password url.

  //los using que use
  using System;
  using System.DirectoryServices;

   try {
        var ldap = new DirectoryEntry("LDAP://tu url AD", "usuario", "password");
        var searcher = new DirectorySearcher(ldap) { Filter = "(objectClass=user)" };

         foreach (SearchResult result in searcher.FindAll())
         {
           DirectoryEntry dirEntry = result.GetDirectoryEntry();
                // Puede encontrar la lista de atributos aquí http://msdn.microsoft.com/en-us/library/ms675090.aspx
                Console.WriteLine("Server name : " + dirEntry.Properties["ServerName"].Value);
                Console.WriteLine("IP : " + dirEntry.Properties["ipHostNumber"].Value);
                Console.WriteLine("User name : " + dirEntry.Properties["sn"].Value);
                Console.WriteLine("Email : " + dirEntry.Properties["mail"].Value);
                Console.WriteLine("Tel : " + dirEntry.Properties["TelephoneNumber"].Value);
                Console.WriteLine("Description : " + dirEntry.Properties["description"].Value);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    
answered by 25.01.2018 в 21:36