Detecting Active Directory in VB.NET...

  • Thread starter Thread starter Chris Roth
  • Start date Start date
C

Chris Roth

Hi All,

Anybody know the best way to detect if network / Active Directory is
present? I'm programming in VB.NET, and my customers often use laptops,
which can be disconnected from the .NET. I need to detect this in order to
be "well behaved."

I've tried putting LDAP://RootDSE in a directory entry constructor. This
works fine in a try catch block, but it is very slow when the net is not
present:
Try

Dim de As New DirectoryEntry("LDAP://RootDSE")

Catch ex As Exception

Debug.WriteLine(ex.Message)

End Try

I tried using the shared method in the DirectoryEntry class to "pre-detect"

If DirectoryEntry.Exists("LDAP://rootDSE") Then ...

but this throws an error when searching for the root - back to square one -
try-catch block, and slow.

Thanks,

Chris.
 
It's slow because, the ADSI client must connect to the LDAP server, when no
network connection is available, the client will throw, but only after a
predefined time-out.
What you could do instead is ping the LDAP server port.
Willy.
 
Anybody know the best way to detect if network / Active Directory is

if you want to make sure a network connection exists, you could have a
look at the SystemInformation.Network property. It's part of the
SystemInformation object, contained in the System.Windows.Forms
namespace.

This however does NOT tell you anything about AD ! It just lets you
know whether or not a network connection exists - that could be an
indication of whether a notebook is docked, or undocked.

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Well, I think that's a good first step, and it's also something I hadn't
quite figured out.

Thanks Marc!

Chris.
 
Well, I think that's a good first step, and it's also something I hadn't
quite figured out.
Thanks Marc!

This gives you an indication whether or not you're even connected to a
network.

I don't have a clear answer in how to easily and quickly detect
whether or not the current connection you have (if you have one) would
be a corporate network with AD - I'll keep you posted.

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top