开发者

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 Directo开发者_如何学CryEntry("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);
        }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜