First thanks for your code.
I'm in trouple with this proplem - API RASConnections.
You know, your code write in Vb6 and a convert it into VB.Net but the result not perfect, when I debug I realize the return of Error code is 87, and I don't know while - I found it in file RasError.h, but I could find anything about this Error code?? Pls help me !!!
Here is my code in VB.Net
'Module Code
Public Structure RasEntryName
Dim dwSize As Long
Dim szEntryName() As Byte
Public Sub init()
ReDim szEntryName(RAS_MaxEntryName)
End Sub
End Structure
Public Structure RasConn
Dim dwSize As Long
Dim hRasConn As Long
Dim szEntryName() As Byte
Dim szDeviceType() As Byte
Dim szDeviceName() As Byte
Public Sub init()
ReDim szEntryName(RAS_MaxEntryName)
ReDim szDeviceType(RAS_MaxDeviceType)
ReDim szDeviceName(RAS_MaxDeviceName)
End Sub
End Structure
Public Declare Function RasEnumConnections Lib _
"rasapi32.dll" Alias "RasEnumConnectionsA" (ByVal lpRasConn As _
RasConn, ByVal lpcb As Long, ByVal lpcConnections As Long) As Long
Public Declare Function RasHangUp Lib "rasapi32.dll" Alias _
"RasHangUpA" (ByVal hRasConn As Long) As Long
Public gstrISPName As String
Public ReturnCode As Long
Public Sub HangUp()
Dim i As Long
Dim lpRasConn(255) As RasConn
For i = 0 To 255
lpRasConn(i).init()
Next
i = 0
Dim lpcb As Long
Dim lpcConnections As Long
Dim hRasConn As Long
lpRasConn(0).dwSize = RAS_RASCONNSIZE
lpcb = RAS_MaxEntryName * lpRasConn(0).dwSize
lpcConnections = 0
ReturnCode = RasEnumConnections(lpRasConn(0), lpcb, _
lpcConnections)
If ReturnCode = ERROR_SUCCESS Then
For i = 0 To lpcConnections - 1
If Trim(ByteToString(lpRasConn(i).szEntryName)) = Trim(gstrISPName) Then
hRasConn = lpRasConn(i).hRasConn
ReturnCode = RasHangUp(hRasConn)
End If
Next i
End If
End Sub
Public Function ByteToString(ByVal bytString() As Byte) As String
Dim i As Integer
ByteToString = ""
i = 0
While bytString(i) = 0&
ByteToString = ByteToString & Chr(bytString(i))
i = i + 1
End While
End Function
Public Sub getConnections()
Call HangUp()
End Sub