powered by simpleCommunicator - 2.0.38     © 2025 Programmizd 02
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / сетевое окружение
4 сообщений из 4, страница 1 из 1
сетевое окружение
    #32225254
Smiler™
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Поиск всех компрьютеров в сети (сетевое окружение) и добавление их в ListBox:
использую такой код...
Option Explicit

Public Type NETRESOURCE

dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As Long
lpRemoteName As Long
lpComment As Long
lpProvider As Long

End Type

Public Declare Function WNetOpenEnum Lib "mpr.dll" Alias "WNetOpenEnumA" (ByVal dwScope As Long, ByVal dwType As Long, ByVal dwUsage As Long, lpNetResource As Any, lphEnum As Long) As Long

Public Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA" (ByVal hEnum As Long, lpcCount As Long, ByVal lpBuffer As Long, lpBufferSize As Long) As Long

Public Declare Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Long) As Long

Public Const RESOURCE_CONNECTED = &H1
Public Const RESOURCE_GLOBALNET = &H2
Public Const RESOURCE_REMEMBERED = &H3

Public Const RESOURCETYPE_ANY = &H0
Public Const RESOURCETYPE_DISK = &H1
Public Const RESOURCETYPE_PRINT = &H2
Public Const RESOURCETYPE_UNKNOWN = &HFFFF

Public Const RESOURCEUSAGE_CONNECTABLE = &H1
Public Const RESOURCEUSAGE_CONTAINER = &H2
Public Const RESOURCEUSAGE_RESERVED = &H80000000

Private Const GMEM_FIXED = &H0
Private Const GMEM_ZEROINIT = &H40
Private Const GPTR = (GMEM_FIXED Or GMEM_ZEROINIT)

Private Declare Function GlobalAlloc Lib "KERNEL32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "KERNEL32" (ByVal hMem As Long) As Long
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function CopyPointer2String Lib "KERNEL32" Alias "lstrcpyA" (ByVal NewString As String, ByVal OldString As Long) As Long

Public Sub DoNetEnum()

Dim hEnum As Long, lpBuff As Long, NR As NETRESOURCE
Dim cbBuff As Long, cCount As Long
Dim p As Long, res As Long, i As Long

'Setup the NETRESOURCE input structure.
NR.lpRemoteName = 0
cbBuff = 10000
cCount = &HFFFFFFFF

'Open a Net enumeration operation handle: hEnum.
res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, NR, hEnum)

If res = 0 Then

'Create a buffer large enough for the results.
'10000 bytes should be sufficient.
lpBuff = GlobalAlloc(GPTR, cbBuff)
'Call the enumeration function.
res = WNetEnumResource(hEnum, cCount, lpBuff, cbBuff)
If res = 0 Then
p = lpBuff
'WNetEnumResource fills the buffer with an array of
'NETRESOURCE structures. Walk through the list and print
'each local and remote name.
For i = 1 To cCount
' All we get back are the Global Network Containers --- Enumerate each of these
CopyMemory NR, ByVal p, LenB(NR)
Form1.List1.AddItem "Network Name " & PointerToString(NR.lpRemoteName)

DoNetEnum2 NR
p = p + LenB(NR)
Next i
End If
If lpBuff <> 0 Then GlobalFree (lpBuff)
WNetCloseEnum (hEnum) 'Close the enumeration

End If

End Sub

Private Function PointerToString(p As Long) As String

'The values returned in the NETRESOURCE structures are pointers to
'ANSI strings so they need to be converted to Visual Basic Strings.

Dim s As String
s = String(255, Chr$(0))
CopyPointer2String s, p
PointerToString = Left(s, InStr(s, Chr$(0)) - 1)

End Function

Public Sub DoNetEnum2(NR As NETRESOURCE)

Dim hEnum As Long, lpBuff As Long
Dim cbBuff As Long, cCount As Long
Dim p As Long, res As Long, i As Long

'Setup the NETRESOURCE input structure.
cbBuff = 10000
cCount = &HFFFFFFFF

'Open a Net enumeration operation handle: hEnum.
res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, NR, hEnum)

If res = 0 Then

'Create a buffer large enough for the results.
'10000 bytes should be sufficient.
lpBuff = GlobalAlloc(GPTR, cbBuff)
'Call the enumeration function.
res = WNetEnumResource(hEnum, cCount, lpBuff, cbBuff)

If res = 0 Then
p = lpBuff
'WNetEnumResource fills the buffer with an array of
'NETRESOURCE structures. Walk through the list and print
'each remote name.
For i = 1 To cCount
CopyMemory NR, ByVal p, LenB(NR)
Form1.List1.AddItem "Network Computer #" & i & " " & PointerToString(NR.lpRemoteName)
p = p + LenB(NR)
Next i
End If

If lpBuff <> 0 Then GlobalFree (lpBuff)
WNetCloseEnum (hEnum) 'Close the enumeration

End If

End Sub

'Place follow code to form section

Private Sub Form_Load()
DoNetEnum
End Sub

Матюхаеться на этом самом красном месте....??? Почему???
...
Рейтинг: 0 / 0
сетевое окружение
    #32225329
кузя
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
замени public на private
...
Рейтинг: 0 / 0
сетевое окружение
    #32225387
Smiler™
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
пробовал....матюхается уже вот тута...


Option Explicit

Public Type NETRESOURCE

dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As Long
lpRemoteName As Long
lpComment As Long
lpProvider As Long

End Type

Public Declare Function WNetOpenEnum Lib "mpr.dll" Alias "WNetOpenEnumA" (ByVal dwScope As Long, ByVal dwType As Long, ByVal dwUsage As Long, lpNetResource As Any, lphEnum As Long) As Long

Public Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA" (ByVal hEnum As Long, lpcCount As Long, ByVal lpBuffer As Long, lpBufferSize As Long) As Long

Public Declare Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Long) As Long

Private Const RESOURCE_CONNECTED = &H1
Private Const RESOURCE_GLOBALNET = &H2
Private Const RESOURCE_REMEMBERED = &H3

Private Const RESOURCETYPE_ANY = &H0
Private Const RESOURCETYPE_DISK = &H1
Private Const RESOURCETYPE_PRINT = &H2
Private Const RESOURCETYPE_UNKNOWN = &HFFFF

Private Const RESOURCEUSAGE_CONNECTABLE = &H1
Private Const RESOURCEUSAGE_CONTAINER = &H2
Private Const RESOURCEUSAGE_RESERVED = &H80000000

Private Const GMEM_FIXED = &H0
Private Const GMEM_ZEROINIT = &H40
Private Const GPTR = (GMEM_FIXED Or GMEM_ZEROINIT)

Private Declare Function GlobalAlloc Lib "KERNEL32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "KERNEL32" (ByVal hMem As Long) As Long
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function CopyPointer2String Lib "KERNEL32" Alias "lstrcpyA" (ByVal NewString As String, ByVal OldString As Long) As Long

Public Sub DoNetEnum()

Dim hEnum As Long, lpBuff As Long, NR As NETRESOURCE
Dim cbBuff As Long, cCount As Long
Dim p As Long, res As Long, i As Long

'Setup the NETRESOURCE input structure.
NR.lpRemoteName = 0
cbBuff = 10000
cCount = &HFFFFFFFF

'Open a Net enumeration operation handle: hEnum.
res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, NR, hEnum)

If res = 0 Then

'Create a buffer large enough for the results.
'10000 bytes should be sufficient.
lpBuff = GlobalAlloc(GPTR, cbBuff)
'Call the enumeration function.
res = WNetEnumResource(hEnum, cCount, lpBuff, cbBuff)
If res = 0 Then
p = lpBuff
'WNetEnumResource fills the buffer with an array of
'NETRESOURCE structures. Walk through the list and print
'each local and remote name.
For i = 1 To cCount
' All we get back are the Global Network Containers --- Enumerate each of these
CopyMemory NR, ByVal p, LenB(NR)
Form1.List1.AddItem "Network Name " & PointerToString(NR.lpRemoteName)

DoNetEnum2 NR
p = p + LenB(NR)
Next i
End If
If lpBuff <> 0 Then GlobalFree (lpBuff)
WNetCloseEnum (hEnum) 'Close the enumeration

End If

End Sub

Private Function PointerToString(p As Long) As String

'The values returned in the NETRESOURCE structures are pointers to
'ANSI strings so they need to be converted to Visual Basic Strings.

Dim s As String
s = String(255, Chr$(0))
CopyPointer2String s, p
PointerToString = Left(s, InStr(s, Chr$(0)) - 1)

End Function

Public Sub DoNetEnum2(NR As NETRESOURCE)

Dim hEnum As Long, lpBuff As Long
Dim cbBuff As Long, cCount As Long
Dim p As Long, res As Long, i As Long

'Setup the NETRESOURCE input structure.
cbBuff = 10000
cCount = &HFFFFFFFF

'Open a Net enumeration operation handle: hEnum.
res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, NR, hEnum)

If res = 0 Then

'Create a buffer large enough for the results.
'10000 bytes should be sufficient.
lpBuff = GlobalAlloc(GPTR, cbBuff)
'Call the enumeration function.
res = WNetEnumResource(hEnum, cCount, lpBuff, cbBuff)

If res = 0 Then
p = lpBuff
'WNetEnumResource fills the buffer with an array of
'NETRESOURCE structures. Walk through the list and print
'each remote name.
For i = 1 To cCount
CopyMemory NR, ByVal p, LenB(NR)
Form1.List1.AddItem "Network Computer #" & i & " " & PointerToString(NR.lpRemoteName)
p = p + LenB(NR)
Next i
End If

If lpBuff <> 0 Then GlobalFree (lpBuff)
WNetCloseEnum (hEnum) 'Close the enumeration

End If

End Sub

'Place follow code to form section

Private Sub Form_Load()
DoNetEnum
End Sub


Мол.... cannot define a Public user-defined type within a private object module
...
Рейтинг: 0 / 0
сетевое окружение
    #32225409
кузя
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
noch ein mal

замени public на private
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / сетевое окружение
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]