Access detailed user account information in AD using VB.Net

One of the challenges on large domains is keeping track of unused accounts, or checking to see if end users passwords have expired.  Now, I know there are several tools out and about that enable you to do this…But come on, where’s the fun in that!?

Using the code detailed below you can query active directory straight from a VB.Net application.

To use this code:

  1. Create a Form in vb.net, call it frmMain
  2. Add a text box to the form to handle the users name, call it txtUsername
  3. Add a text box to the form, set it to multiline = true, call it txtDetails
  4. Add a command button to the form, call it cmdGo
  5. Copy and paste the code below into the code editor
  6. Add a reference to the ‘System.DirectoryServices.AccountManagement’ .Net add-in
  7. Modify the line:

    To include your domain name and domain controllers name.  So, for instance, if your domain controller was called SBSserver, and your domain name was Dom1 then you would need to edit the line to read:

Now the code below is quite basic/limited but this gives you access to the currentADuser object, which you can use autocomplete to show you just what it can do. You may also notice that the code below is geared more towards searching more then one account.  This was extracted from a much larger project, after spending too long searching the net trying to find solutions to issues with the findall command.

If you do find the code useful and decide to use it in your project, drop me a comment below and let me know how it goes.

Mike Hudson

Mike Hudson is a Lead Cyber Security Analyst living and working in Kingston Upon Hull. With extensive experience in Microsoft and Apple technologies, ranging from desktop OS’s to Server OS’s and hardware. By day working as part of an infrastructure team, and by night ridding the world of IT issues through blog posts..

%d bloggers like this: