Detecting Active Directory in VB.NET...

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.
 
W

Willy Denoyette [MVP]

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.
 
M

Marc Scheuner [MVP ADSI]

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
 
C

Chris Roth

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

Thanks Marc!

Chris.
 
M

Marc Scheuner [MVP ADSI]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top