2014-03-13 4 views
0

저는 도메인 사용자로 실행되는 코드에서 Active Directory의 LDAP 서버 URL을 가져 오는 방법을 찾고있었습니다. 가능한 경우 disjoint namespace으로 코드가 올바르게 작동해야합니다. 그것은 관리되지 않는 코드이므로 .NET 솔루션은 불행히도 옵션이 아닙니다. 바인딩 어떤 이유로 서버를 사용하지 LDAP://DC=mycompany,DC=local를 사용할 때 ADO 쿼리를 인정 One or more errors occurred during processing of command 오류를 반환이 경우 작동하지 않는 것 들어 Windows API를 사용하여 Active Directory의 LDAP 서버 URL을 얻으려면 어떻게해야합니까?

(즉 rootDSE 개체의 defaultNamingContext 속성의 값이다).

LOGONSERVERUSERDNSDOMAIN 환경 변수를 사용하면 코드가 SYSTEM 계정에서 실행될 수 있어야하고 거기에 이러한 변수가 없기 때문에 옵션으로 표시되지 않습니다.

모든 아이디어 나 힌트 또는 구체적인 RTFM 조언을 보내 주시면 감사하겠습니다.

업데이트 : DNSHostName 속성이 rootDSE 인 것으로 보입니다.

답변

1

이 내용은 Visual Basic 스크립트 (VBS)입니다. 코드를 .vbs 파일로 저장하고 ANSI charset을 사용하십시오. 이 스크립트는 오래되었지만 더 나은 솔루션으로 안내 할 수 있습니다.

Set cn = CreateObject("ADODB.Connection") 
Set cmd= CreateObject("ADODB.Command") 
cn.Provider = "ADsDSOObject;" 
cn.open 
cmd.ActiveConnection = cn 

' Root DSE required to get the default configuration naming context to 
' be used as the root of the seach 
set objRootDSE = getobject("LDAP://RootDSE") 
' Construct the LDAP query that will find all the domain controllers 
' in the domain 
ldapQuery = "<LDAP://" & objRootDSE.Get("ConfigurationNamingContext") & _ 
    ">;((objectClass=nTDSDSA));ADsPath;subtree" 

cmd.CommandText = ldapQuery 
cmd.Properties("Page Size") = 1000 
Set rs = cmd.Execute 

do while rs.EOF <> True and rs.BOF <> True 
    ' Bind to the domain controller computer object 
    ' (This is the parent object of the result from the query) 
    set objDC = getobject(getobject(rs(0)).Parent) 

    wscript.echo objDC.dNSHostName 
     rs.MoveNext 
Loop 

cn.close 
+0

제안 해 주셔서 감사합니다. – gdy

0

rootDSE의 DNSHostName 속성이 필요한 것 같습니다.

관련 문제