| View previous topic :: View next topic |
| Author |
Message |
Philwn Freshman
Joined: 25 Feb 2004 Posts: 40 Location: England
|
Posted: Feb 25th, 2004 04:36 PM Post subject: network |
|
|
is it possible to fetch all computers connected to a local area network on form load? basically as i open my program i want a drop down list to automatically fill with all computer names on the network so the user can jus select the one cud anyone help with this, bearing in mind it first time im attempting VB for about 6 months some of u may rememba me from when this forum was at www.hotvbforum.com _________________ Nothing good to put here |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Feb 25th, 2004 06:45 PM Post subject: |
|
|
Hey, good to see you again
Have a look at this :
[vb:1:e6cb1d5337]'IN A MODULE
Option Explicit
Public Type SERVER_INFO_100
sv100_platform_id As Long
sv100_name As Long
End Type
Public Const SV_TYPE_DOMAIN_ENUM As Long = &H80000000
Public Const SV_TYPE_ALL As Long = &HFFFFFFFF
Public Const MAX_PREFERRED_LENGTH As Long = -1
Public Const NERR_SUCCESS As Long = 0&
Public Const ERROR_REQ_NOT_ACCEP = 71&
Public Const ERROR_MORE_DATA As Long = 234&
Public Const NERR_BASE = 2100
Public Const NERR_InvalidComputer = (NERR_BASE + 251)
Public Declare Function NetServerEnum Lib "netapi32" (ByVal servername As Long, ByVal level As Long, buf As Any, _
ByVal prefmaxlen As Long, entriesread As Long, totalentries As Long, ByVal servertype As Long, ByVal domain As Long, _
resume_handle As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
Public Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As Long) As Long
Public Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Public Function GetServers(sDomain As String, sType As Long) As String()
Dim bufptr As Long
Dim dwEntriesread As Long
Dim dwTotalentries As Long
Dim dwResumehandle As Long
Dim se100 As SERVER_INFO_100
Dim success As Long
Dim nStructSize As Long
Dim Cnt As Long
nStructSize = LenB(se100)
success = NetServerEnum(0&, 100, bufptr, MAX_PREFERRED_LENGTH, dwEntriesread, dwTotalentries, sType, StrPtr(sDomain), dwResumehandle)
'success = 71 'NO ACTIVE 'DOMAIN'
If success = NERR_SUCCESS And success <> ERROR_MORE_DATA Then
Dim compNames() As String
ReDim compNames(dwEntriesread)
For Cnt = 0 To dwEntriesread - 1
CopyMemory se100, ByVal bufptr + (nStructSize * Cnt), nStructSize
compNames(Cnt) = GetPointerToByteStringW(se100.sv100_name)
DoEvents
Next
End If
Call NetApiBufferFree(bufptr)
GetServers = compNames
End Function
Public Function GetPointerToByteStringW(ByVal dwData As Long) As String
Dim tmp() As Byte
Dim tmplen As Long
If dwData <> 0 Then
tmplen = lstrlenW(dwData) * 2
If tmplen <> 0 Then
ReDim tmp(0 To (tmplen - 1)) As Byte
CopyMemory tmp(0), ByVal dwData, tmplen
GetPointerToByteStringW = tmp
End If
End If
End Function
'BEHIND A FORM WITH TWO COMBOS (cboDomain AND cboComputer)
Private Sub Form_Load()
Dim compNames() As String
Dim x As Integer
'SETUP THE DOMAIN COMBO BOX
compNames = GetServers(vbNullString, SV_TYPE_DOMAIN_ENUM)
For x = LBound(compNames) To UBound(compNames) - 1
cboDomain.AddItem compNames(x)
Next
cboDomain.ListIndex = 0
End Sub
Private Sub cboDomain_Click()
'NEED TO CLEAR CBOCOMPUTER AND RELOAD WITH COMPUTERS IN THE NEWLY SELECTED DOMAIN
'SETUP THE COMPUTER COMBO BOX
On Error GoTo No_Bugs
Dim compNames() As String
Dim x As Integer
cboComputer.Clear
x = 0
compNames = GetServers(cboDomain.Text, SV_TYPE_ALL)
If UBound(compNames) > 0 Then
For x = LBound(compNames) To UBound(compNames) - 1
cboComputer.AddItem compNames(x)
Next
cboComputer.ListIndex = 0
End If
Exit Sub
No_Bugs:
If Err.Number = "9" Then
cboDomain.RemoveItem (cboDomain.ListIndex)
cboDomain.ListIndex = 0
compNames = GetServers(cboDomain.Text, SV_TYPE_ALL)
Resume
Else
MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation, App.ProductName
End If
End Sub[/vb:1:e6cb1d5337]
I haven't tested it... Let me know if it works  _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
Philwn Freshman
Joined: 25 Feb 2004 Posts: 40 Location: England
|
Posted: Feb 26th, 2004 03:18 AM Post subject: yep |
|
|
that works gr8 thanks u made me a happy guy . lol glad to see your still on here and i also see your a moderator too now so well done _________________ Nothing good to put here |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Feb 26th, 2004 08:19 AM Post subject: |
|
|
Thanks
If I remember correctly you were an expert when we were at HVBF, right? _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
Philwn Freshman
Joined: 25 Feb 2004 Posts: 40 Location: England
|
Posted: Feb 27th, 2004 03:16 AM Post subject: |
|
|
that wot it ranked me as yeh but i duno y i only managed to help ppl with the simple problems or ones i had asked few weeks before hand. But i am only 17 teaching myself VB from home in my spare time which means bout 2-3 hours a week so as u can understand it take time to build up good knowledge of VB especially seen as how i stopped for 6 months n only just started again. basically the way i learn is i think of a little program that can do sumthin n try n code it myself n slight problems i have i ask on here. your solution was gr8 thnx but wud be beta if i understood most of it but i havent had time to read thru it yet _________________ Nothing good to put here |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Feb 27th, 2004 05:57 PM Post subject: |
|
|
Well that's what we're here for Any trouble you run into we'll be glad to help you out with it I also taught myself VB through forums and I'd like to think I know a fair amount of VB So keep working on it  _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
|