怎样获得局域网所有的计算机名

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

怎样获得局域网所有的计算机名

新加一treeview控件, 命名为TrvComputer,再加一imagelist1

代码如下:

Option Explicit

Dim strComputerName As String

Private Const RESOURCE_CONNECTED As Long = &H1&

Private Const RESOURCE_GLOBALNET As Long = &H2&

Private Const RESOURCE_REMEMBERED As Long = &H3&

Private Const RESOURCEDISPLAYTYPE_DIRECTORY& = &H9

Private Const RESOURCEDISPLAYTYPE_DOMAIN& = &H1

Private Const RESOURCEDISPLAYTYPE_FILE& = &H4

Private Const RESOURCEDISPLAYTYPE_GENERIC& = &H0

Private Const RESOURCEDISPLAYTYPE_GROUP& = &H5

Private Const RESOURCEDISPLAYTYPE_NETWORK& = &H6

Private Const RESOURCEDISPLAYTYPE_ROOT& = &H7

Private Const RESOURCEDISPLAYTYPE_SERVER& = &H2

Private Const RESOURCEDISPLAYTYPE_SHARE& = &H3

Private Const RESOURCEDISPLAYTYPE_SHAREADMIN& = &H8 Private Const RESOURCETYPE_ANY As Long = &H0&

Private Const RESOURCETYPE_DISK As Long = &H1&

Private Const RESOURCETYPE_PRINT As Long = &H2&

Private Const RESOURCETYPE_UNKNOWN As Long = &HFFFF& Private Const RESOURCEUSAGE_ALL As Long = &H0&

Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1& Private Const RESOURCEUSAGE_CONTAINER As Long = &H2& Private Const RESOURCEUSAGE_RESERVED As Long = &H80000000 Private Const NO_ERROR = 0

Private Const ERROR_MORE_DATA = 234 'L // dderror

Private Const RESOURCE_ENUM_ALL As Long = &HFFFF

Private Type NETRESOURCE

dwScope As Long

dwType As Long

dwDisplayType As Long

dwUsage As Long

pLocalName As Long

pRemoteName As Long

pComment As Long

pProvider As Long

End Type

Private Type NETRESOURCE_REAL

dwScope As Long

dwType As Long

dwUsage As Long

sLocalName As String

sRemoteName As String

sComment As String

sProvider As String

End Type

Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Declare Function GetComputerNameW Lib "kernel32" (lpBuffer As Any, nSize As Long) As Long

Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long

Private 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

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

Private Declare Function VarPtrAny Lib "vb40032.dll" Alias "VarPtr" (lpObject As Any) As Long Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (lpTo As Any, lpFrom As Any, ByVal lLen As Long)

Private Declare Sub CopyMemByPtr Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpTo As Long, ByVal lpFrom As Long, ByVal lLen As Long)

Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Any) As Long

Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long

Sub GetLocalInfo()

Dim nodX As Node

Const MAX_RESOURCES = 256

Const NOT_A_CONTAINER = -1

Dim bFirstTime As Boolean

Dim lReturn As Long

Dim hEnum As Long

Dim lCount As Long

Dim lMin As Long

Dim lLength As Long

Dim l As Long

Dim lBufferSize As Long

相关文档
最新文档