Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA for getting the DC 1

Status
Not open for further replies.

scotttom

IS-IT--Management
Mar 5, 2002
143
US
Two questions really.....

I've got an Access front end and a SQL 2005 back end.

We are replicating our SQL data to a second server in another state and I want to determine which SQL sever users will use by identifying the DC that they authenticated to.

First, does my idea make sense? And if so how do I it?

Thanks in advance for any assistance.

Scott
 
how about
Code:
Public Function GetADDistinguishedName(CurrentUserName)
Dim objConnection As ADODB.Connection
Dim objCommand As ADODB.Command
Dim objRecordset As ADODB.Recordset
Dim struser As String
Dim strGroup
Dim objUser
Dim objGroup
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.ConnectionTimeout = 0
objCommand.CommandTimeout = 0
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://BrightSmile' WHERE  sAMAccountName ='" & CurrentUserName & "'"
Set objRecordset = objCommand.Execute
objRecordset.MoveFirst
GetADDistinguishedName = objRecordset!distinguishedName
 
OK Thanks pwise, but this looks like it returns the distinguished name of an object on an LDAP server. Is that right?

Basically what I think I need to do is to find out what Domain Controller a user is authenticated to when the application launches. Based on that I'm going to point them to an appropriate SQL server.

Does my approach make sense and how would I get the name or IP address of the authenticating DC from VBA in and Access mdb file?

Thanks again for any help.

 
You can get the domain controller that authenticated the logon by viewing the LOGONSERVER environment variable.

eg Debug.Print Environ ("LOGONSERVER")

You need to ignore the two \\ symbols at the start for the server name, but that is it.
If the Environ (LogonServer) without the two \\ characters is the same as Environ ("COMPUTERNAME") then it is a local rather than domain logon.

John
 
Fantastic! Thanks jrbarnett. I really appreciate it.

Best,

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top