Определение компьютеров в сети - VB
Формулировка задачи:
Люди, подскажите пожалуйста как программно определить список компьютеров, которые сейчас в сети.
Решение задачи: «Определение компьютеров в сети»
textual
Листинг программы
Const MAX_RESOURCES = 256 Const NOT_A_CONTAINER = -1 Function StringFromPtr(Ptr As Long) As String Dim lLength As Long lLength = lstrlen(Ptr) StringFromPtr = Space$(lLength) CopyMem ByVal StringFromPtr, ByVal Ptr, lLength End Function Public Sub EnumNetworks() Dim lRet As Long Dim hEnum As Long Dim lCount As Long Dim Ind As Long Dim lBufferSize As Long Dim uNet(0 To MAX_RESOURCES - 1) As NETRESOURCE lRet = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, RESOURCEUSAGE_ALL, ByVal 0&, hEnum) If lRet = NO_ERROR Then lCount = RESOURCE_ENUM_ALL Do lBufferSize = Len(uNet(0)) * MAX_RESOURCES lRet = WNetEnumResource(hEnum, lCount, uNet(0), lBufferSize) If lCount > 0 Then For Ind = 0 To lCount - 1 If uNet(Ind).dwDisplayType = RESOURCEDISPLAYTYPE_NETWORK Then frmMain.lblNetwork = StringFromPtr(uNet(Ind).pRemoteName) DoEvents EnumDomains uNet(Ind) End If Next Ind End If Loop While lRet = ERROR_MORE_DATA End If If hEnum Then WNetCloseEnum hEnum End Sub Private Sub EnumDomains(ByRef Parent As NETRESOURCE) Dim lRet As Long Dim hEnum As Long Dim lCount As Long Dim Ind As Long Dim lBufferSize As Long Dim uNet(0 To MAX_RESOURCES - 1) As NETRESOURCE lRet = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, RESOURCEUSAGE_ALL, Parent, hEnum) If lRet = NO_ERROR Then lCount = RESOURCE_ENUM_ALL Do lBufferSize = Len(uNet(0)) * MAX_RESOURCES lRet = WNetEnumResource(hEnum, lCount, uNet(0), lBufferSize) If lCount > 0 Then For Ind = 0 To lCount - 1 If uNet(Ind).dwDisplayType = RESOURCEDISPLAYTYPE_DOMAIN Then frmMain.lblDomain = StringFromPtr(uNet(Ind).pRemoteName) DoEvents EnumServers uNet(Ind) End If Next Ind End If Loop While lRet = ERROR_MORE_DATA End If If hEnum Then WNetCloseEnum hEnum End Sub Private Sub EnumServers(ByRef Parent As NETRESOURCE) Dim lRet As Long Dim hEnum As Long Dim lCount As Long Dim Ind As Long Dim lBufferSize As Long Dim uNet(0 To MAX_RESOURCES - 1) As NETRESOURCE Dim Srv As String lRet = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, RESOURCEUSAGE_ALL, Parent, hEnum) If lRet = NO_ERROR Then lCount = RESOURCE_ENUM_ALL Do lBufferSize = Len(uNet(0)) * MAX_RESOURCES lRet = WNetEnumResource(hEnum, lCount, uNet(0), lBufferSize) If lCount > 0 Then For Ind = 0 To lCount - 1 If uNet(Ind).dwDisplayType = RESOURCEDISPLAYTYPE_SERVER Then Srv = StringFromPtr(uNet(Ind).pRemoteName) frmMain.lblServer = Srv DoEvents <... тут код по обработке компьютера Srv ...> End If Next Ind End If Loop While lRet = ERROR_MORE_DATA End If If hEnum Then WNetCloseEnum hEnum End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д