470,612 Members | 2,178 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,612 developers. It's quick & easy.

Retrieve Domain Names

Dan
All,

I need to be able to retrieve a list of Domains that are part of our network: similar to the list you get when you log onto a Windows station that is part of a domain.

I assume that I can get this via Active Directory but being somewhat new to that I am not sure where it is or how to get at it.

Any help is appreciated. Thanks!

Dan
Nov 20 '05 #1
2 1208
Answer provided by Mr. Ken Tucker. Let me know if it helps.

Hi,

This will only work if you are connected to an active directory. Add
a reference to system.directoryservices. Replace NetworkName with your
network name.

Dim de As New
System.DirectoryServices.DirectoryEntry("LDAP://NetworkName")

Dim ds As New System.DirectoryServices.DirectorySearcher(de)

Dim r As System.DirectoryServices.SearchResult

ds.Filter = "(objectClass=computer)"

Try

For Each r In ds.FindAll

Dim s As String

Console.WriteLine(r.GetDirectoryEntry.Name.ToStrin g)

Next

Catch e As Exception

Console.WriteLine(e.ToString)

End Try
This NetServerEnum api will work for a network without a domain. I
pasted the code for a sample console app below.

Imports System.Runtime.InteropServices

Module Module1

Structure Computer_info_101

Public Platform_ID As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Name As String

Public Version_Major As Integer

Public Version_Minor As Integer

Public Type As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Comment As String

End Structure

Declare Unicode Function NetServerEnum Lib "Netapi32.dll" _

(ByVal Servername As Integer, ByVal level As Integer, _

ByRef buffer As Integer, ByVal PrefMaxLen As Integer, _

ByRef EntriesRead As Integer, ByRef TotalEntries As Integer, _

ByVal ServerType As Integer, ByVal DomainName As String, _

ByRef ResumeHandle As Integer) As Integer

Declare Function NetApiBufferFree Lib "Netapi32.dll" _

(ByVal lpBuffer As Integer) As Integer

Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers

Sub Main()

Dim ComputerInfo As Computer_info_101

Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, ResumeHandle
As
Integer

Dim BufPtr As Integer

Dim iPtr As IntPtr

MaxLenPref = -1

level = 101

ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead,
TotalEntries,
_

SV_TYPE_SERVER, "MSHOME", ResumeHandle) ' Replace MSHOME with your
workgroup
name

If ret <> 0 Then

Console.WriteLine("An Error has occured")

Return

End If

' loop thru the entries

For i = 0 To EntriesRead - 1

' copy the stuff into our structure

Dim ptr As IntPtr = New IntPtr(BufPtr)

computerInfo = CType(Marshal.PtrToStructure(ptr,
GetType(Computer_info_101)), _

Computer_info_101)

BufPtr = BufPtr + Len(ComputerInfo)

Console.WriteLine(computerInfo.Name)

Next

NetApiBufferFree(BufPtr)

Console.Write("Press Enter to End")

Dim s As String = Console.ReadLine()

End Sub

End Module

"Dan" <Da*@discussions.microsoft.com> wrote in message
news:BF**********************************@microsof t.com:
All,

I need to be able to retrieve a list of Domains that are part of our
network: similar to the list you get when you log onto a Windows station
that is part of a domain.

I assume that I can get this via Active Directory but being somewhat new
to that I am not sure where it is or how to get at it.

Any help is appreciated. Thanks!

Dan


Nov 20 '05 #2
"Dan" <Da*@discussions.microsoft.com> schrieb

I need to be able to retrieve a list of Domains that are part of our
network: similar to the list you get when you log onto a Windows
station that is part of a domain.

I assume that I can get this via Active Directory but being somewhat
new to that I am not sure where it is or how to get at it.

There's no VB.Net command for this. Maybe you'll get an answer in one of the
..Net Framework groups: microsoft.public.dotnet.framework.*
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Resell Domain Names | last post: by
16 posts views Thread by Terry Burns | last post: by
3 posts views Thread by Jeff Waskiewicz | last post: by
reply views Thread by conniezhang | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.