PDA

Click to See Complete Forum and Search --> : Access Network NeighbourHood from VB


taraf
Oct 7th, 1999, 11:28 AM
I want to access the Network Neighbourhood inside my application.

I need to access all the PCs in the NtkNeighbourhood, so that the user
of my application can select a PC of his choice.

Can any one tell me how to display all the PCs in the neighbourhood ?

------------------

wgilster
Oct 8th, 1999, 11:39 AM
Use the API calls WNETOpenEnum and WNetEnumResource.

Type NetResource
dwScope As NetResourceScope
dwType As NetResourceType
dwDisplayType As NetResourceDisplayType
dwUsage As NetResourceUsage
lpLocalName As Long
lpRemoteName As Long
lpComment As Long
lpProvider As Long
End Type
dim nr as NetResource

NetworkError = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0,0 ,hEnum)

NetworkError = WNetEnumResource(hEnum, cCount, nr(0), cbBuff)

I have created a network neighborhood look-a-like with these routines.

Wes G.

Dec 16th, 1999, 02:17 AM
Could someone please put in more detail on doing this.

I am making a comparison program and I need access to the network neighborhood. at the moment that code screws up, I added some code to it like the API calls and then I custommly put in teh type but still no good!

Is it possible to get some working code and maybe some example project or something for it.

Please help me

Aaron Young
Dec 16th, 1999, 03:11 AM
Here's one I just finished, it displays a Browse Dialog of the Network Neighbourhood and Returns the Name of the Computer Selected..

In a Module..

Private Type SHITEMID
cb As Long
abID As Byte
End Type

Private Type ITEMIDLIST
mkid As SHITEMID
End Type

Private Type BROWSEINFO
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BROWSEINFO) As Long
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)

Private Const FLDR_NETWORK = &H12
Private Const BIF_BROWSEFORCOMPUTER = 4096

Public Function BrowseNetwork(ByVal lHwnd As Long, ByVal sTitle As String) As String
Dim tIDL As ITEMIDLIST
Dim lIDList As Long
Dim sBuffer As String
Dim tBI As BROWSEINFO
Dim sComputer As String
Dim lFolder As Long

lret = SHGetSpecialFolderLocation(0, FLDR_NETWORK, tIDL)

sComputer = Space(260)
With tBI
.hwndOwner = lHwnd
.pIDLRoot = tIDL.mkid.cb
.lpszTitle = lstrcat(sTitle, "")
.ulFlags = BIF_BROWSEFORCOMPUTER
.pszDisplayName = StrPtr(sComputer)
End With

lIDList = SHBrowseForFolder(tBI)

sComputer = StrConv(sComputer, vbUnicode)
BrowseNetwork = Left(sComputer, InStr(sComputer, Chr(0)) - 1)
Call CoTaskMemFree(lIDList)
End Function

In the Form..

Private Sub Command1_Click()
Caption = BrowseNetwork(hWnd, "Select a Computer..")
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net