❶ 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=資料庫的用戶名;