我用WebBrowser 访问内网的其他机器,比如说:192.168.1.6
使用的方法是:WebBrowser1.Navigate2 "\\192.168.1.6",
但是如果内网中 192.168.1.6 这个地址不存在,那么,就会出现好几十秒种的死机现象?请问有没有办法先判断这个地址到底“可达”不啊?如果可达,就用WebBrowser1.Navigate2 "\\192.168.1.6"语句,如果不可达,则提示没这个地址这个怎么实现啊?
使用的方法是:WebBrowser1.Navigate2 "\\192.168.1.6",
但是如果内网中 192.168.1.6 这个地址不存在,那么,就会出现好几十秒种的死机现象?请问有没有办法先判断这个地址到底“可达”不啊?如果可达,就用WebBrowser1.Navigate2 "\\192.168.1.6"语句,如果不可达,则提示没这个地址这个怎么实现啊?
解决方案 »
- 如何截获软件封包并模拟发包?
- VB中的回车为什么必须是 chr(10) & chr(13),为何 chr(13)不行?
- 怎样让其它程序在我的一个窗体中运行?
- 如何让msgbox窗口出现在指定的位置?
- 如何给TabStrip添加一个DblClick事件到事件列表框中?
- 一个简单的问题,急。。在线等
- 看到 yoki(小马哥) 的sqlserver还原的代码,可是搞不懂,急求解....................100分
- 串口通讯问题,如何实现Com1,com2同时通讯,接收两个不同终端的数据?在线等待
- 在VB里如何调用shell32.dll,谢谢。
- 高手快出手,怎么修改注册表的某一个键名称?(不是值)
- 关于vb3.0的问题,急,在线等
- vb能不能同时连接两个数据库
'Form1
Option Explicit 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 Private Sub Form_click()
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.dwUsage = RESOURCEUSAGE_CONTAINER
nr.lpRemoteName = 0
cbBuff = 1000
cCount = &HFFFFFFFF 'Open a Net enumeration operation handle: hEnum.
res = WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, _
0, nr, hEnum)
If res = 0 Then
'Create a buffer large enough for the results.
'1000 bytes should be sufficient.
lpBuff = GlobalAlloc(GPTR, cbBuff)
'Call the enumeration function.
res = WNetEnumResource(hEnum, cCount, lpBuff, cbBuff)
If res = 0 Then
p = lpBuff
Cls
'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
CopyMemory nr, ByVal p, LenB(nr)
p = p + LenB(nr)
Print PointerToString(nr.lpLocalName), _
PointerToString(nr.lpRemoteName)
Next i
Else
MsgBox "Error: " & Err.LastDllError, vbOKOnly, _
"WNetEnumResources"
End If
If lpBuff <> 0 Then GlobalFree (lpBuff)
WNetCloseEnum (hEnum) 'Close the enumeration
Else
MsgBox "Error: " & Err.LastDllError, vbOKOnly, "WNetOpenEnum"
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'Module1
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 'RESOURCE ENUMERATION.
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
每台机器都设置了共享用户名密码的,他们要求在软件里提示用户名、密码,使用软件要用统一密码进去。也就是说,内网IP是事先存放在数据库里的,不能动态搜索。你这个是个好方法,请指教一下怎么调用,让我多学一找,呵呵,谢谢。
//上面的代码在Form_Click事件内把所有的局域网内的所有IP Print到Form上你把他保存到文件或者数据库即可!
http://support.microsoft.com/?kbid=177697
只支持
• Microsoft Windows NT 3.51 Service Pack 5
• Microsoft Windows NT 4.0 Service Pack 7
• Microsoft Windows 95 Service Pack 1
• Microsoft Win32 Software Development Kit (SDK)
• Microsoft Windows 2000 Standard Edition
• Microsoft Windows Millennium Edition
试试
http://vbnet.mvps.org/index.html?code/network/netserverenum.htm
'添加List和CommandButton各一控件
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ?1996-2004 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Windows type used to call the Net API
Private Const MAX_PREFERRED_LENGTH As Long = -1
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&Private Const SV_TYPE_WORKSTATION As Long = &H1
Private Const SV_TYPE_SERVER As Long = &H2
Private Const SV_TYPE_SQLSERVER As Long = &H4
Private Const SV_TYPE_DOMAIN_CTRL As Long = &H8
Private Const SV_TYPE_DOMAIN_BAKCTRL As Long = &H10
Private Const SV_TYPE_TIME_SOURCE As Long = &H20
Private Const SV_TYPE_AFP As Long = &H40
Private Const SV_TYPE_NOVELL As Long = &H80
Private Const SV_TYPE_DOMAIN_MEMBER As Long = &H100
Private Const SV_TYPE_PRINTQ_SERVER As Long = &H200
Private Const SV_TYPE_DIALIN_SERVER As Long = &H400
Private Const SV_TYPE_XENIX_SERVER As Long = &H800
Private Const SV_TYPE_SERVER_UNIX As Long = SV_TYPE_XENIX_SERVER
Private Const SV_TYPE_NT As Long = &H1000
Private Const SV_TYPE_WFW As Long = &H2000
Private Const SV_TYPE_SERVER_MFPN As Long = &H4000
Private Const SV_TYPE_SERVER_NT As Long = &H8000
Private Const SV_TYPE_POTENTIAL_BROWSER As Long = &H10000
Private Const SV_TYPE_BACKUP_BROWSER As Long = &H20000
Private Const SV_TYPE_MASTER_BROWSER As Long = &H40000
Private Const SV_TYPE_DOMAIN_MASTER As Long = &H80000
Private Const SV_TYPE_SERVER_OSF As Long = &H100000
Private Const SV_TYPE_SERVER_VMS As Long = &H200000
Private Const SV_TYPE_WINDOWS As Long = &H400000 'Windows95 and above
Private Const SV_TYPE_DFS As Long = &H800000 'Root of a DFS tree
Private Const SV_TYPE_CLUSTER_NT As Long = &H1000000 'NT Cluster
Private Const SV_TYPE_TERMINALSERVER As Long = &H2000000 'Terminal Server
Private Const SV_TYPE_DCE As Long = &H10000000 'IBM DSS
Private Const SV_TYPE_ALTERNATE_XPORT As Long = &H20000000 'rtn alternate transport
Private Const SV_TYPE_LOCAL_LIST_ONLY As Long = &H40000000 'rtn local only
Private Const SV_TYPE_DOMAIN_ENUM As Long = &H80000000
Private Const SV_TYPE_ALL As Long = &HFFFFFFFFPrivate Const SV_PLATFORM_ID_OS2 As Long = 400
Private Const SV_PLATFORM_ID_NT As Long = 500'Mask applied to svX_version_major in
'order to obtain the major version number.
Private Const MAJOR_VERSION_MASK As Long = &HFPrivate Type SERVER_INFO_100
sv100_platform_id As Long
sv100_name As Long
End TypePrivate 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 LongPrivate Declare Function NetApiBufferFree Lib "netapi32" _
(ByVal Buffer As Long) As LongPrivate Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(pTo As Any, uFrom As Any, _
ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32" _
(ByVal lpString As Long) As Long
Private Sub Form_Load() Command1.Caption = "Net Server Enum"End Sub
Private Sub Command1_Click() Call GetServers(vbNullString)
End Sub
Private Function GetServers(sDomain As String) As Long 'lists all servers of the specified type
'that are visible in a domain.
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)
'Call passing MAX_PREFERRED_LENGTH to have the
'API allocate required memory for the return values.
'
'The call is enumerating all machines on the
'network (SV_TYPE_ALL); however, by Or'ing
'specific bit masks for defined types you can
'customize the returned data. For example, a
'value of 0x00000003 combines the bit masks for
'SV_TYPE_WORKSTATION (0x00000001) and
'SV_TYPE_SERVER (0x00000002).
'
'dwServerName must be Null. The level parameter
'(100 here) specifies the data structure being
'used (in this case a SERVER_INFO_100 structure).
'
'The domain member is passed as Null, indicating
'machines on the primary domain are to be retrieved.
'If you decide to use this member, pass
'StrPtr("domain name"), not the string itself.
success = NetServerEnum(0&, _
100, _
bufptr, _
MAX_PREFERRED_LENGTH, _
dwEntriesread, _
dwTotalentries, _
SV_TYPE_ALL, _
0&, _
dwResumehandle) 'if all goes well
If success = NERR_SUCCESS And _
success <> ERROR_MORE_DATA Then
'loop through the returned data, adding each
'machine to the list
For cnt = 0 To dwEntriesread - 1
'get one chunk of data and cast
'into an SERVER_INFO_100 struct
'in order to add the name to a list
CopyMemory se100, ByVal bufptr + (nStructSize * cnt), nStructSize
List1.AddItem GetPointerToByteStringW(se100.sv100_name)
Next
End If
'clean up regardless of success
Call NetApiBufferFree(bufptr)
'return entries as sign of success
GetServers = dwEntriesreadEnd 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