By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

How to bind to DC depending on site

P: n/a
I'm trying to bind to DC by site. The environment is a AD 2K3 domain with
multiple sites.

For example, when my application is started, it checks for the site of the
computer where the application is running. Then, it looks for a DC in the
site and then all DirectorySearcher and DIrectoryEntry operations will use a
binding string aimed at that DC on the site.

If the DC is not available, then a default server, the PDC emulator is used.

How would I code in VB .Net the following:

1) Determine which site the current PC running my application is in.
2) Determine which domain controllers are in the site.
3) Bind directly to the domain controller on the site using
DirectoryServices.DirectoryEntry or DirectoryServices.DirectorySearcher

It's just that I don't trust the automatic DC selection when performing
directory operations.
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
NC,
Why don't you trust "automatic DC selection"? When a user initializes a
logon, a DC in his/her site should answer the request and allow them access;
that DC's name will be stored in the %LOGONSERVER% variable. Any subsequent
request should go to this DC first, which is what you want to do, right?
Jared
"Net Coder" <ne***************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I'm trying to bind to DC by site. The environment is a AD 2K3 domain with
multiple sites.

For example, when my application is started, it checks for the site of the
computer where the application is running. Then, it looks for a DC in the
site and then all DirectorySearcher and DIrectoryEntry operations will use
a binding string aimed at that DC on the site.

If the DC is not available, then a default server, the PDC emulator is
used.

How would I code in VB .Net the following:

1) Determine which site the current PC running my application is in.
2) Determine which domain controllers are in the site.
3) Bind directly to the domain controller on the site using
DirectoryServices.DirectoryEntry or DirectoryServices.DirectorySearcher

It's just that I don't trust the automatic DC selection when performing
directory operations.

Nov 20 '05 #2

P: n/a


Jared wrote:
NC,
Why don't you trust "automatic DC selection"? When a user initializes a
logon, a DC in his/her site should answer the request and allow them access;
that DC's name will be stored in the %LOGONSERVER% variable. Any subsequent
request should go to this DC first, which is what you want to do, right?
Jared


Well, yes I want to bind to a DC on the site and have it guaranteed that I
always use the DC on the site for all AD queries. You see, my application
creates user accounts and then uses the information in the user account,
like the SID, immediately. With replication lag, and if the wrong DC on the
site is selected, the user account will not be on the DC which is being queried.

For example, if you create a user account on a DC and then try to create a
share immediately on another server and adjust the ACL on the share to
contain an ACE with the new user's SID, you might find that the lookup uses
a different DC on the site leading to the failure to create the share.
Nov 20 '05 #3

P: n/a
Net Coder wrote:
I'm trying to bind to DC by site. The environment is a AD 2K3 domain
with multiple sites.

For example, when my application is started, it checks for the site of
the computer where the application is running. Then, it looks for a DC
in the site and then all DirectorySearcher and DIrectoryEntry operations
will use a binding string aimed at that DC on the site.

If the DC is not available, then a default server, the PDC emulator is
used.

How would I code in VB .Net the following:

1) Determine which site the current PC running my application is in.
2) Determine which domain controllers are in the site.
3) Bind directly to the domain controller on the site using
DirectoryServices.DirectoryEntry or DirectoryServices.DirectorySearcher

It's just that I don't trust the automatic DC selection when performing
directory operations.

Hi

Step 1) and 2) with a vbscript:
'--------------------8<----------------------

' Get sitename of current computer
sSiteName = CreateObject("ADSystemInfo").SiteName

' Find domain controller in this site
Set oRootDSE = GetObject("LDAP://RootDSE")
Set oSubnetsCont = _
GetObject("LDAP://cn=Servers,cn=" & sSiteName & ",cn=sites," _
& oRootDSE.Get("configurationNamingContext") )

oSubnetsCont.Filter = Array("server")
sServerName = "" ' Init value
For Each oSubnet In oSubnetsCont
sServerName = oSubnet.Get("cn")
Exit For ' exit loop after first find
Next

If sServerName = "" Then
WScript.Echo "No server is defined in this site"
Else
WScript.Echo "Server defined in this site: " & sServerName
End If
'--------------------8<----------------------
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scr...r/default.mspx
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.