| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3499 人关注过本帖, 1 人收藏
标题:VB如何判断计算机是否连网(麻烦用Ping的方法解决)
只看楼主 加入收藏
kisme
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-8-14
收藏(1)
 问题点数:0 回复次数:3 
VB如何判断计算机是否连网(麻烦用Ping的方法解决)
VB如何判断计算机是否连网(麻烦用Ping的方法解决)

谢谢啦
搜索更多相关主题的帖子: 计算机 Ping 连网 麻烦 判断 
2006-08-14 19:13
学习VB才2天
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1653
专家分:0
注 册:2006-5-4
收藏
得分:0 

判断是否已经连网:
首先新建一.BAS

Public Declare Function InternetGetConnectedState _
Lib "wininet.dll" (ByRef dwFlags As Long, _
ByVal dwReserved As Long) As Long
'Local system uses a modem to connect to the Internet.
Public Const INTERNET_CONNECTION_MODEM As Long = &H1
'Local system uses a LAN to connect to the Internet.
Public Const INTERNET_CONNECTION_LAN As Long = &H2
'Local system uses a proxy server to connect to the Internet.
Public Const INTERNET_CONNECTION_PROXY As Long = &H4
'No longer used.
Public Const INTERNET_CONNECTION_MODEM_BUSY As Long = &H8
Public Const INTERNET_RAS_INSTALLED As Long = &H10
Public Const INTERNET_CONNECTION_OFFLINE As Long = &H20
Public Const INTERNET_CONNECTION_CONFIGURED As Long = &H40
'InternetGetConnectedState wrapper functions
Public Function IsNetConnectViaLAN() As Boolean
Dim dwflags As Long
'pass an empty variable into which the API will
'return the flags associated with the connection
Call InternetGetConnectedState(dwflags, 0&)
'return True if the flags indicate a LAN connection
IsNetConnectViaLAN = dwflags And INTERNET_CONNECTION_LAN
End Function
Public Function IsNetConnectViaModem() As Boolean
Dim dwflags As Long
'pass an empty variable into which the API will
'return the flags associated with the connection
Call InternetGetConnectedState(dwflags, 0&)
'return True if the flags indicate a modem connection
IsNetConnectViaModem = dwflags And INTERNET_CONNECTION_MODEM
End Function
Public Function IsNetConnectViaProxy() As Boolean
Dim dwflags As Long
'pass an empty variable into which the API will
'return the flags associated with the connection
Call InternetGetConnectedState(dwflags, 0&)
'return True if the flags indicate a proxy connection
IsNetConnectViaProxy = dwflags And INTERNET_CONNECTION_PROXY
End Function
Public Function IsNetConnectOnline() As Boolean
'no flags needed here - the API returns True.
'if there is a connection of any type
IsNetConnectOnline = InternetGetConnectedState(0&, 0&)
End Function
Public Function IsNetRASInstalled() As Boolean
Dim dwflags As Long
'pass an empty variable into which the API will
'return the flags associated with the connection
Call InternetGetConnectedState(dwflags, 0&)
'return True if the flags include RAS installed
IsNetRASInstalled = dwflags And INTERNET_RAS_INSTALLED
End Function
Public Function GetNetConnectString() As String
Dim dwflags As Long
Dim msg As String
'build a string for display
If InternetGetConnectedState(dwflags, 0&) Then
If dwflags And INTERNET_CONNECTION_CONFIGURED Then
msg = msg & "You have a network connection configured." & vbCrLf
End If
If dwflags And INTERNET_CONNECTION_LAN Then
msg = msg & "The local system connects to the Internet via a LAN"
End If
If dwflags And INTERNET_CONNECTION_PROXY Then
msg = msg & ", and uses a proxy server. "
Else: msg = msg & "."
End If

If dwflags And INTERNET_CONNECTION_MODEM Then
msg = msg & "The local system uses a modem to connect to the Internet. "
End If

If dwflags And INTERNET_CONNECTION_OFFLINE Then
msg = msg & "The connection is currently offline. "

End If

If dwflags And INTERNET_CONNECTION_MODEM_BUSY Then
msg = msg & "The local system's modem is busy with a non-Internet connection. "
End If

If dwflags And INTERNET_RAS_INSTALLED Then
msg = msg & "Remote Access Services are installed on this system."
End If

Else

msg = "Not connected to the internet now."

End If

GetNetConnectString = msg

End Function
'--end block--'

接着在FORM1里面加入一个Command,六个text box ,text的Multiline都设置成真.
--------------------------------------------------------------------------------
Option Explicit
Private Sub Command1_Click()
Text1.Text = IsNetConnectViaLAN()
Text2.Text = IsNetConnectViaModem()
Text3.Text = IsNetConnectViaProxy()
Text4.Text = IsNetConnectOnline()
Text5.Text = IsNetRASInstalled()
Text6.Text = GetNetConnectString()

End Sub

[此贴子已经被作者于2006-8-16 10:18:07编辑过]


[GLOW=255,DeepPink,3]我的免费网盘[/GLOW]
2006-08-16 10:06
yuwei526
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-8-2
收藏
得分:0 
厉害,挺好用

我顶你个肺
2006-08-17 13:57
freeforever
Rank: 4
等 级:业余侠客
威 望:3
帖 子:368
专家分:201
注 册:2005-11-2
收藏
得分:0 
好帖,谢谢楼主提供。

其实我也很无聊!
2006-08-21 10:11
快速回复:VB如何判断计算机是否连网(麻烦用Ping的方法解决)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.056571 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved