Автор вопроса: Justas | Web-сайт:justas.newmail.ru | ICQ: 259418212
Всем привет.
Народ, вот какой вопрос: на машине настроено 3 интернет-соединения, юзер может выходить в интернет под любым из них. (хочу заблокировать одно из соединений.) Как узнать что машина в коннекте я себе представляю, а вот как узнать имя текущего соединения? Помню что где-то здесь уже такое видел, только искать долго не получается (с интернетом проблемы :(( )
nRet = RasEnumConnections(lpRasConn(0), lpcb, lpcConnections) If Not nRet = 0 Then MsgBox WinErrorMsg(nRet) End If End Sub
Function IsConnected Alias "IsConnected"() Export As Long Function = Not (lpRasConn(0).hRasConn = 0&) End Function
Function GetConName Alias "GetConName"() Export As String Function = lpRasConn(0).szEntryName End Function
Function GetDeviceName Alias "GetDeviceName"() Export As String GetDeviceName = lpRasConn(0).szDeviceName End Function
Function GetDeviceType Alias "GetDeviceType"() Export As String GetDeviceType = LCase$(lpRasConn(0).szDeviceTYPE) End Function
Function GetNumInfo Alias "GetNumInfo"() Export As String Function = "All" End Function
' ----------------------------- Инициализация dll библиотеки -----------------------------------
Function DllMain(ByVal hInstance As Long, ByVal Reason As Long, ByVal Reserved As Long) As Long If Reason = %DLL_PROCESS_ATTACH Then g_hInstance = hInstance End If
Function = 1& End Function
VB
Option Explicit Private Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (lpRasconn As Any, lpcb As Long, lpcConnections As Long) As Long Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type VBRASCONN hRasConn As Long sEntryName As String sDeviceType As String sDeviceName As String sPhonebook As String lngSubEntry As Long guidEntry(15) As Byte End Type Private Declare Function GetProfStr Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal sSection As String, ByVal sKey As Any, ByVal sDefault As String, ByVal sValue As String, ByVal nSize As Long, ByVal sFileName As String) As Long Private sConName As String, bIsConnected As Boolean, sDeviceName As String, sDeviceType As String
Public Sub UpdateData() Dim rtn As Long, b() As Byte, ras_i As Long Dim aLens As Variant, dwSize As Long Dim lpcb As Long, lpConns As Long Dim aVBRasConns() As VBRASCONN
For ras_i = 0 To 3 dwSize = aLens(ras_i) Call CopyMemory(b(0), dwSize, &H4): lpcb = 4 rtn = RasEnumConnections(b(0), lpcb, lpConns) If Not rtn = 632 And Not rtn = 610 Then Exit For Next If lpConns = 0 Then Exit Sub
Option Explicit Private Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (lpRasconn As Any, lpcb As Long, lpcConnections As Long) As Long Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type VBRASCONN hRasConn As Long sEntryName As String sDeviceType As String sDeviceName As String sPhonebook As String lngSubEntry As Long guidEntry(15) As Byte End Type Private Declare Function GetProfStr Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal sSection As String, ByVal sKey As Any, ByVal sDefault As String, ByVal sValue As String, ByVal nSize As Long, ByVal sFileName As String) As Long Private sConName As String, bIsConnected As Boolean, sDeviceName As String, sDeviceType As String
Public Sub UpdateData() Dim rtn As Long, b() As Byte, ras_i As Long Dim aLens As Variant, dwSize As Long Dim lpcb As Long, lpConns As Long Dim aVBRasConns() As VBRASCONN
For ras_i = 0 To 3 dwSize = aLens(ras_i) Call CopyMemory(b(0), dwSize, &H4): lpcb = 4 rtn = RasEnumConnections(b(0), lpcb, lpConns) If Not rtn = 632 And Not rtn = 610 Then Exit For Next If lpConns = 0 Then Exit Sub
Private Const RAS_MAXENTRYNAME As Integer = 256 Private Const RAS_MAXDEVICETYPE As Integer = 16 Private Const RAS_MAXDEVICENAME As Integer = 128 Private Const RAS_RASCONNSIZE As Integer = 412 Private Type RASCONN dwSize As Long hRasConn As Long szEntryName(RAS_MAXENTRYNAME) As Byte szDeviceType(RAS_MAXDEVICETYPE) As Byte szDeviceName(RAS_MAXDEVICENAME) As Byte End Type Private Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (udtRasConn As Any, lpcb As Long, lpcConnections As Long) As Long
Private Sub Command1_Click() Dim udtRasConn(255) As RASCONN, countConn As Long Dim Ret As Long, b As Long udtRasConn(0).dwSize = RAS_RASCONNSIZE Ret = RasEnumConnections(udtRasConn(0), RAS_MAXENTRYNAME * udtRasConn(0).dwSize, countConn) If Ret = 0 Then For b = 0 To countConn - 1 MsgBox "Текущее соединение: " & StrConv(udtRasConn(b).szEntryName(), vbUnicode) Next b End If End Sub