#Region "Add Domain Servers To Text File"
Public Function GetNetList(ByVal DomainName As String) As String()
Dim ServerInfo As New Server_info_101()
Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, _
ResumeHandle As Integer
Dim BufPtr As New IntPtr()
Dim iPtr As IntPtr
Dim tempPtr As Integer
Dim ans(0) As String
Dim sw As StreamWriter
If File.Exists(Application.StartupPath & "\Servers.txt") = True Then
Dim sr1 As StreamReader = File.OpenText(Application.StartupPath & _
"\Servers.txt")
Do Until sr1.Peek = -1
frmMoveUser.lstboxServers.Items.Add(sr1.ReadLine)
Loop
Exit Function
End If
sw = File.CreateText(Application.StartupPath & "\Servers.txt")
Const SV_TYPE_DOMAIN_CTRL As Long = &H8
Const SV_TYPE_DOMAIN_BAKCTRL As Long = &H10
' let's do it!
MaxLenPref = -1
level = 101
ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead, _
TotalEntries, SV_TYPE_ALL, DomainName, ResumeHandle)
If ret <> 0 Then
MsgBox("Hmmmm... something went wrong", vbCritical, "Error!")
Return ans
End If
Dim nSize As Integer = Marshal.SizeOf(ServerInfo)
ReDim ans(EntriesRead - 1)
tempPtr = BufPtr.ToInt32
' loop thru the entries
For i = 0 To EntriesRead - 1
' copy the stuff into our structure
iPtr = New IntPtr(BufPtr.ToInt32 + i * nSize)
ServerInfo = CType(Marshal.PtrToStructure(iPtr, _
GetType(Server_info_101)), Server_info_101)
' Output ServerName to our text file.
If ServerInfo.Type = 266291 Or _
ServerInfo.Type = 266259 Or _
ServerInfo.Type = 102435 Or _
ServerInfo.Type = 102403 Then
sw.WriteLine(ServerInfo.Name)
End If
Next
NetApiBufferFree(iPtr)
NetApiBufferFree(BufPtr)
sw.Close()
Dim sr As StreamReader = File.OpenText(Application.StartupPath & _
"\Servers.txt")
Do Until sr.Peek = -1
frmMoveUser.lstboxServers.Items.Add(sr.ReadLine)
Loop
sr.Close()
End Function
#End Region