I am looking for some code in either vb or C# to locate the DNS server, the Global Catalog server and the primary domain controller. Please, don't offer links unless they actually articulate source code. I am comfortable with AD programming and can find all computers as demonstrated below, but I just want to find servers with specific purposes.
Public Function GetCatalogServer() As String
Dim oDE As DirectoryEntry
Dim oSearch As DirectorySearcher
Dim oResults As SearchResultCollection
oDE = GetDirectoryObject("Default")
oSearch = New DirectorySearcher(oDE)
oSearch.PageSize = 1000
oSearch.Filter = "(objectClass=Computer)"
oSearch.SearchScope = SearchScope.Subtree
oResults = oSearch.FindAll()
Catch ex As Exception
Me.Severity = 3