怎样用VB得知系统当前是否处于internet链结状态? 如何读取这个键值,并得知系统是否与internet相连。 '声明以下函数变量常量: Public Const ERROR_SUCCESS = 0& Public Const APINULL = 0& Public Const HKEY_LOCAL_MACHINE = &H80000002 Public ReturnCode As Long Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Declare Function RegQueryvalueEx Lib "advapi32.dll" Alias "RegQueryvalueExA" (ByVal hKey As Long, ByVal lpvalueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long '代码: Public Function ActiveConnection() As Boolean Dim hKey As Long Dim lpSubKey As String Dim phkResult As Long Dim lpvalueName As String Dim lpReserved As Long Dim lpType As Long Dim lpData As Long Dim lpcbData As Long ActiveConnection = False lpSubKey = "System\CurrentControlSet\Services\RemoteAccess" ReturnCode = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, phkResult) If ReturnCode = ERROR_SUCCESS Then hKey = phkResult lpvalueName = "Remote Connection" lpReserved = APINULL lpType = APINULL lpData = APINULL lpcbData = APINULL ReturnCode = RegQueryvalueEx(hKey, lpvalueName, lpReserved, lpType, ByVal lpData, lpcbData) lpcbData = Len(lpData) ReturnCode = RegQueryvalueEx(hKey, lpvalueName, lpReserved, lpType, lpData, lpcbData) If ReturnCode = ERROR_SUCCESS Then If lpData = 0 Then ActiveConnection = False Else ActiveConnection = True End If End If RegCloseKey (hKey) End If End Function '下面是使用以上代码的例子: If ActiveConnection = True Then Call MsgBox("现在处于链结状态。", vbInformation) Else Call MsgBox("现在处于断开状态。", vbInformation) End If看看合适不,合适就给分吧,争取年前冲星!!
新建一个工程,选择->工程->部件->控件选项卡中的"Microsoft Winsock Control 6.0" 在窗口中加入一个Winsock控件,一个按钮. 代码如下:Private Sub Command1_Click() If Winsock1.LocalIP = "0.0.0.0" Or Winsock1.LocalIP = "127.0.0.1" Then MsgBox "本地连接失败,请检查网线是否插好!" Else MsgBox "本地连接正常!OK" End IfEnd Sub
其实这个可以检测到的采用wmi具体的可以看下面的代码 strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\wmi") Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("Select * from MSNdis_StatusMediaDisconnect") Do While True Set strLatestEvent = colMonitoredEvents.NextEvent msgbox "朋友网线掉了:"
Loop网线接回来 strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\wmi") Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("Select * from MSNdis_StatusMediaConnect") Do While True Set strLatestEvent = colMonitoredEvents.NextEvent msgbox "好了 连接 ok"
如何读取这个键值,并得知系统是否与internet相连。
'声明以下函数变量常量:
Public Const ERROR_SUCCESS = 0&
Public Const APINULL = 0&
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public ReturnCode As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegQueryvalueEx Lib "advapi32.dll" Alias "RegQueryvalueExA" (ByVal hKey As Long, ByVal lpvalueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
'代码:
Public Function ActiveConnection() As Boolean
Dim hKey As Long
Dim lpSubKey As String
Dim phkResult As Long
Dim lpvalueName As String
Dim lpReserved As Long
Dim lpType As Long
Dim lpData As Long
Dim lpcbData As Long
ActiveConnection = False
lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
ReturnCode = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, phkResult)
If ReturnCode = ERROR_SUCCESS Then
hKey = phkResult
lpvalueName = "Remote Connection"
lpReserved = APINULL
lpType = APINULL
lpData = APINULL
lpcbData = APINULL
ReturnCode = RegQueryvalueEx(hKey, lpvalueName, lpReserved, lpType, ByVal lpData, lpcbData)
lpcbData = Len(lpData)
ReturnCode = RegQueryvalueEx(hKey, lpvalueName, lpReserved, lpType, lpData, lpcbData)
If ReturnCode = ERROR_SUCCESS Then
If lpData = 0 Then
ActiveConnection = False
Else
ActiveConnection = True
End If
End If
RegCloseKey (hKey)
End If
End Function
'下面是使用以上代码的例子:
If ActiveConnection = True Then
Call MsgBox("现在处于链结状态。", vbInformation)
Else
Call MsgBox("现在处于断开状态。", vbInformation)
End If看看合适不,合适就给分吧,争取年前冲星!!
若发现有“网线没插好”图标时,表示此时网线没插好
甚至可以拦截文本绘制API
等Windows系统提示网线没插好时会弹出一气泡提示,该气泡提示会调用文本绘制API输出文字“网线没插好……”
以此类推,还可以找到很多种“解决方案”
但都不符合实际
在窗口中加入一个Winsock控件,一个按钮.
代码如下:Private Sub Command1_Click()
If Winsock1.LocalIP = "0.0.0.0" Or Winsock1.LocalIP = "127.0.0.1" Then
MsgBox "本地连接失败,请检查网线是否插好!"
Else
MsgBox "本地连接正常!OK"
End IfEnd Sub
strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\wmi")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("Select * from MSNdis_StatusMediaDisconnect") Do While True
Set strLatestEvent = colMonitoredEvents.NextEvent
msgbox "朋友网线掉了:"
Loop网线接回来
strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\wmi")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("Select * from MSNdis_StatusMediaConnect") Do While True
Set strLatestEvent = colMonitoredEvents.NextEvent
msgbox "好了 连接 ok"
Loop