❶ vb 怎么检测网络连接的名称

一行代码

LinkName$=CreateObject("Wscript.Shell").RegRead("HKLM\SOFTWARE\Microsoft\RAS AutoDial\Default\DefaultInternet")

执行完成后,字符串变量LinkName中,就是你的默认连接的名称

如果你的连接不是默认连接,可以在注册表相同位置寻找,所有的连接名称都在那附近,用同上的方法一样可以读到

❷ vb中获取本地或已连接的一个资源的网络名称

WNetGetConnection

VB声明
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
说明
获取本地或已连接的一个资源的网络名称
返回值
Long,零表示成功。会设置GetLastError。如GetLastError是ERROR_EXTENDED_ERROR,则可用WNetGetLastError取得额外的错误信息
参数表
参数 类型及说明
lpszLocalName String,本地设备的名字
lpszRemoteName String,指定一个字串缓冲区,用于装载设备的资源名称
cbRemoteName Long,lpszRemoteName缓冲区的字符数量。如缓冲区不够大,则设为需要的缓冲区长度

❸ VB 获取网络时间方法

下面是一个比较完整的获取网络时间的代码,自动判断网络没连接或者连接失败类情况,不用on Error Resume Next:

Private Sub Command1_Click()
Dim obj, OBJStatus, url, GetText, i
Dim Retrieval
url = "http://www.163.com"
'判断网络是否连接
If url <> "" Then
Set Retrieval = GetObject("winmgmts:\\.\root\cimv2")
Set obj = Retrieval.ExecQuery("Select * From Win32_PingStatus Where Address = '" & Mid(url, 8) & "'")
For Each OBJStatus In obj
If IsNull(OBJStatus.StatusCode) Or OBJStatus.StatusCode <> 0 Then
Exit Sub
Else
Exit For '已连接则继续
End If
Next
End If

'通过下载网页头信息获取网络时间
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.setRequestHeader "If-Modified-Since", "0"
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Connection", "close"
.Send
If .Readystate <> 4 Then Exit Sub
GetText = .getAllResponseHeaders()
i = InStr(1, GetText, "date:", vbTextCompare)
If i > 0 Then '网页下载成功
i = InStr(i, GetText, ",", vbTextCompare)
GetText = Trim(Mid(GetText, i + 1))
i = InStr(1, GetText, " GMT", vbTextCompare)
GetText = Left(GetText, i - 1)
MsgBox "网络时间:" & GetText
End If
End With
Set Retrieval = Nothing
Set OBJStatus = Nothing
Set obj = Nothing
End Sub

❹ vb怎么判断网络是否已经连接上

GetHostbyName API可获取域名对应的地址,当没有联网状态将会返回一个错误值。所以可利用它来判断是否联网。

Private Sub Form_Load()
If IsConnectedState Then
MsgBox "连接网络"
Else
MsgBox "没有联网"
End If
End Sub

VBScript code复制代码

Option Explicit

Private Type WSADATA
wversion As Integer
wHighVersion As Integer
szDescription(0 To 256) As Byte
szSystemStatus(0 To 128) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpszVendorInfo As Long
End Type

Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Integer, lpWSAData As WSADATA) As Long
Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal szHostname As String) As Long
Private Const WS_VERSION_REQD = &H101

Public Function IsConnectedState() As Boolean
Dim udtWSAD As WSADATA
Call WSAStartup(WS_VERSION_REQD, udtWSAD)
IsConnectedState = CBool(gethostbyname("www..com"))
Call WSACleanup
End Function

❺ vb怎样查看网络连接状态

Winsock.state 是显示当前Winsock 和另一主机连接的状态,它不是显示主机网络信息的.

用InternetGetConnectedState() 函数可以实现.为了方便你调用下面给模快代码你吧..

Private Declare Function InternetGetConnectedState Lib "Wininet.dll" (ByVal Flag As Long, ByVal Reserved As Long) As Long
Public Type Rtn_InetStat
IsConnecting As Boolean
IsModenConnecting As Boolean
IsModenBusy As Boolean
IsLANConnecting As Boolean
IsProxyConnecting As Boolean
End Type
Public Function RtnInetStat() As Rtn_InetStat
RtnInetStat.IsConnecting = RtnNunBooleanA(InternetGetConnectedState(0, 0))
RtnInetStat.IsModenConnecting = RtnNunBooleanB(InternetGetConnectedState(1, 0))
RtnInetStat.IsLANConnecting = RtnNunBooleanB(InternetGetConnectedState(2, 0))
RtnInetStat.IsProxyConnecting = RtnNunBooleanA(InternetGetConnectedState(4, 0))
RtnInetStat.IsModenBusy = RtnNunBooleanA(InternetGetConnectedState(8, 0))
End Function
Private Function RtnNunBooleanA(ByVal Num As Long) As Boolean
If Num = 0 Then
RtnNunBooleanA = False
Else
RtnNunBooleanA = True
End If
End Function
Private Function RtnNunBooleanB(ByVal Num As Long) As Boolean
If Num = 0 Then
RtnNunBooleanB = True
Else
RtnNunBooleanB = False
End If
End Function

获取当前网络是否已连接上:
Msgbox RtnInetStat.IsConnecting

❻ vb中连接网络

Shell "Rasphone.exe -h " & "连接名称"
如果不知道连接名称,可以用如下代码,先获取网络连接名称及在线状态

Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Long, ByVal dwReserved As Long) As Long

Private Property Get OnLine(ln As String) As Boolean
ln = String$(128, 0)
OnLine = InternetGetConnectedStateEx(0, ln, 128, 0&)
End Property

Private Sub Command1_Click()
Dim LinkName As String
If OnLine(LinkName) Then Shell "Rasphone.exe -h " & LinkName
End Sub

shell "rasdial.exe 连接名称 /disconnect",1
就是在网络属性里你创建网络拨号的那个连接名称呀

挂断所有网络连接
Private Declare Function RasHangUp Lib "RasApi32.DLL" Alias "RasHangUpA" (ByVal hRasConn As Long) As Long
Private Declare Function RasEnumConnections Lib "RasApi32.DLL" Alias "RasEnumConnectionsA" (lprasconn As Any, lpcb As Long, lpcConnections As Long) As Long

Const RAS95_MaxEntryName = 256
Const RAS95_MaxDeviceName = 128
Const RAS_MaxDeviceType = 16

Private Type RASCONN95
dwSize As Long
hRasConn As Long
szEntryName(RAS95_MaxEntryName) As Byte
szDeviceType(RAS_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type

Private Sub Command1_Click()
Dim lngRetCode As Long
Dim lpcb As Long
Dim lpcConnections As Long
Dim intArraySize As Integer
Dim intLooper As Integer
ReDim lprasconn95(intArraySize) As RASCONN95
lprasconn95(0).dwSize = 412
lpcb = 256 * lprasconn95(0).dwSize
lngRetCode = RasEnumConnections(lprasconn95(0), lpcb, lpcConnections)
If lngRetCode = 0 Then
If lpcConnections > 0 Then
For intLooper = 0 To lpcConnections - 1
RasHangUp lprasconn95(intLooper).hRasConn
Next intLooper
MsgBox "完毕", 64
Else
MsgBox "没有拨号网络连接!", 48
End If
End If
End Sub

调用方法:
拨号:temp = AddConnection("连接名", "", "", username, Password, "") 'ADSL
temp=0 成功,否则失败
断线: HangUpAll

❼ VB怎么检查网络连接状态

如果是检查winsock的连接状态可以用,if winsock1.state=*
sckClosed 0 缺省的。关闭
sckOpen 1 打开
sckListening 2 侦听
sckConnectionPending 3 连接挂起
sckResolvingHost 4 识别主机
sckHostResolved 5 已识别主机
sckConnecting 6 正在连接
sckConnected 7 已连接
sckClosing 8 同级人员正在关闭连接
sckError 9 错误

*值得就是上述值的一个,然后在后面添加代码!例如要判断时候关闭,就可以
if winsock1.state=0 then msgbox "未连接!"
这样的没有连接就会弹出对话框了

❽ vb怎么查看电脑是否连接到网络

GetHostbyNameAPI可获取域名对应的IP地址,当没有联网状态将会返回一个错误值。所以可利用它来判断是否联网。

PrivateSubForm_Load()
IfIsConnectedStateThen
MsgBox"连接网络"
Else
MsgBox"没有联网"
EndIf
EndSub

VBScriptcode复制代码

OptionExplicit

PrivateTypeWSADATA
wversionAsInteger
wHighVersionAsInteger
szDescription(0To256)AsByte
szSystemStatus(0To128)AsByte
iMaxSocketsAsInteger
iMaxUdpDgAsInteger
lpszVendorInfoAsLong
EndType

"WSOCK32.DLL"(,lpWSADataAsWSADATA)AsLong
"WSOCK32.DLL"()AsLong
"WSOCK32.DLL"(ByValszHostnameAsString)AsLong
PrivateConstWS_VERSION_REQD=&H101

()AsBoolean
DimudtWSADAsWSADATA
CallWSAStartup(WS_VERSION_REQD,udtWSAD)
IsConnectedState=CBool(gethostbyname("www..com"))
CallWSACleanup
EndFunction

❾ VB 获取 网络连接 列表

代码如下,不过要给分啊!^_^
Option Explicit
'检测本机是否联入互联网,以及以什么形式联入

Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" _
Alias "InternetGetConnectedStateExA" _
(ByRef lpdwFlags As Long, _
ByVal lpszConnectionName As String, _
ByVal dwNameLen As Long, _
ByVal dwReserved As Long _
) As Long

Private Enum EIGCInternetConnectionState
INTERNET_CONNECTION_MODEM = &H1&
INTERNET_CONNECTION_LAN = &H2&
INTERNET_CONNECTION_PROXY = &H4&
INTERNET_RAS_INSTALLED = &H10&
INTERNET_CONNECTION_OFFLINE = &H20&
INTERNET_CONNECTION_CONFIGURED = &H40&
End Enum

Private Function InternetConnected(Optional ByRef eConnectionInfo _
As EIGCInternetConnectionState, Optional ByRef _
sConnectionName As String) As Boolean

Dim dwFlags As Long
Dim sNameBuf As String
Dim lR As Long
Dim iPos As Long

On Error Resume Next

sNameBuf = String$(513, 0)
lR = InternetGetConnectedStateEx(dwFlags, sNameBuf, 512, 0&)
eConnectionInfo = dwFlags
iPos = InStr(sNameBuf, vbNullChar)
If iPos > 0 Then
sConnectionName = Left$(sNameBuf, iPos - 1)
ElseIf Not sNameBuf = String$(513, 0) Then
sConnectionName = sNameBuf
End If
InternetConnected = (lR = 1)

End Function

Public Function IsInNet() As Boolean

'检测是否已经以及使用什么方法连接到Internet
Dim bConnected As Boolean
Dim eR As Long
Dim sName As String
Dim sMsg As String

bConnected = InternetConnected(eR, sName)

'根据获得的结果输出
' If (eR And INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM Then
' sMsg = sMsg & "使用modem连接到Internet."
' End If
'
' If (eR And INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN Then
' sMsg = sMsg & "使用内部网连接到Internet."
' End If
'
' If (eR And INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY Then
' sMsg = sMsg & "通过代理服务器连接到Internet."
' End If
'
' If (eR And INTERNET_CONNECTION_OFFLINE) = INTERNET_CONNECTION_OFFLINE Then
' sMsg = sMsg & "现在连接处于离线状态."
' End If
'
' If (eR And INTERNET_CONNECTION_CONFIGURED) = INTERNET_CONNECTION_CONFIGURED Then
' sMsg = sMsg & "连接已经被设定."
' Else
' sMsg = sMsg & "没有设定好的连接."
' End If
'
' If (eR And INTERNET_RAS_INSTALLED) = INTERNET_RAS_INSTALLED Then
' sMsg = sMsg & "本机已经安装了远程访问服务功能."
' End If

IsInNet = bConnected

End Function

如果直接调用,可以通过返回值判断是否联网;如果将其中的注释去掉,还可以得到连网的种类等详细信息。酷吧?

❿ VB获取网络SQL数据!

和VB正常提取数据库内数据一样,只是连接字符串里,将服务器名称写成"127.0.0.1",不用管服务器的用户名和密码。
反正我们是这么做的,下面是连接字符串的内容。
Driver={mySQL};
Server=127.0.0.1;
Port=3306;Option=131072;
Stmt=;
Database=mydb;Uid=数据库的用户名;
Pwd=数据库的用户名;