user576137
user576137

Reputation: 11

Auth as administrator

I've done an application that basically goes through all active users on a network via DirectoryEntry, where I'm able to get each computers Username (login id), this is done by DE.UserName (DirectoryEntry).

Alright, so far so good, now with my problem; whenever I try to fetch it's password it's throwing an exception saying I need to have admin rights in order to get the password of each connected pc.

I am not the owner of the network, so I'm wondering if there's any way to auth as an admin or change your group to Administrator, or in any way bypass this so I can access it's password?

Code:

 DirectoryEntry computers = new DirectoryEntry("WinNT://JBVAS");//The domain
        IEnumerator enumerator = computers.Children.GetEnumerator();
        while(enumerator.MoveNext())
        {
            DirectoryEntry entry = enumerator.Current as DirectoryEntry;
            Console.WriteLine("Username: {0}{1}Password: {2}",
                entry.Username, Environment.NewLine, entry.Password);
        }

Upvotes: 1

Views: 287

Answers (1)

Uwe Keim
Uwe Keim

Reputation: 40736

You could use impersonation to make your code (temporary) run under a higher privileged user.

I wrote an easy-to-use impersonation class some years back, you can find it over at CodeProject.com.

An example could be:

using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) )
{
   // code that executes under the new context
}

Put your Active Directory code that needs administrator permissions inside the using block.

Upvotes: 1

Related Questions