Here's some sample codes. How can I get the UserName of an internet
connection? (vb 2005)
Declare Function RasGetEntryDialParams Lib "rasapi32.dll" Alias
"RasGetEntryDialParamsA" (ByVal lpcstr As String, ByRef lprasdialparamsa As
RASDIALPARAMS, ByRef lpbool As Long) As Long
Declare Function RasDial Lib "rasapi32.dll" Alias "RasDialA" (ByVal
lprasdialextensions As Long, ByVal lpcstr As String, ByRef lprasdialparamsa
As RASDIALPARAMS, ByVal dword As Long, ByVal lpvoid As Any, ByRef lphrasconn
As Long) As Long
Private Declare Function InternetDial Lib "wininet.dll" Alias
"InternetDialA" (ByVal hwndParent As Long, ByVal lpszConnectoid As String,
ByVal dwFlags As Long, ByVal lpdwConnection As Long, ByVal dwReserved As
Long) As Long
Private Declare Function InternetGoOnline Lib "wininet.dll" Alias
"InternetGoOnlineA" (ByVal lpszURL As String, ByVal hwndParent As Long,
ByVal dwReserved As Long) As Long
Private Declare Function InternetHangUp Lib "wininet.dll" (ByVal
dwConnection As Long, ByVal dwReserved As Long) As Long
Private Declare Function InternetAutodial Lib "wininet.dll" (ByVal
dwFlags As Long, ByVal hwndParent As Long) As Long
Private Declare Function InternetAutodialHangup Lib "wininet.dll" (ByVal
dwReserved As Long) As Long
Private Declare Function InternetOpen Lib "wininet.dll" Alias
"InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal
sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As
Long
Private Declare Function InternetConnect Lib "wininet.dll" Alias
"InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As
String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal
sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal
lContext As Long) As Long
Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll"
Alias "InternetGetLastResponseInfoA" (ByVal lpdwError As Long, ByVal
lpszBuffer As String, ByVal lpdwBufferLength As Long) As Boolean
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile
As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, ByVal
lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal
hInet As Long) As Integer
Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll"
Alias "InternetGetConnectedStateExA" (ByVal lpdwFlags As Long, ByVal
lpszConnectionName As Long, ByVal dwNameLen As Long, ByVal dwReserved As
Long) As Long
Declare Function RasHangUp Lib "rasapi32.dll" Alias "RasHangUpA" (ByVal
hRasConn As Long) As Long
Declare Function RasGetErrorString Lib "rasapi32.dll" Alias
"RasGetErrorStringA" (ByVal uErrorValue As Long, ByVal lpszErrorString As
String, ByVal cBufSize As Long) As Long
'---------------------------------
'----------------------------------
'-----------------------------------
Okay, your declarations seem to be from classic vb (with longs instead
of integers) so I went through pinvoke.net and msdn and updated them
for you. I have not checked any of these, as I don't have any code
demonstrating how to use them - and I didn't feel like writing any.
<StructLayout(LayoutKind.Sequential)> _
Public Structure RASDIALPARAMS
Public dwSize As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=257)> Public
szEntryName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=129)> Public
szPhoneNumber As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=129)> Public
szCallbackNumber As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=257)> Public
szUserName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=257)> Public
szPassword As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> Public
szDomain As String
Public dwSubEntry As UInt32
Public dwCallbackId As IntPtr
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure RASDIALEXTENSIONS
Public dwSize As Integer
Public dwfOptions As UInt32
Public hWndParent As IntPtr
Public reserved As Integer
Public reserved1 As Integer
Public RasEapInfo As RASEAPINFO
End Structure
Public Structure RASEAPINFO
Public dsSizeofEapInfo As Integer
Public pbEapInfo As Byte
End Structure
<DllImport("rasapi32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function RasGetEntryDialParams(ByVal lpszPhonebook
As String, _
<[In](), Out()> ByRef
lprasdialparams As RASDIALPARAMS, _
<Out()> ByRef
lpfPassword As Boolean) As Integer
End Function
<DllImport("rasapi32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function RasDial(<[In]()> ByVal lpRasDialExtensions
As RASDIALEXTENSIONS, _
<[In]()> ByVal lpszPhonebook As
String, _
<[In]()> ByVal lpRasDialParams As
RASDIALPARAMS, _
ByVal dwNotifierType As UInt32, _
ByVal lpvNotifier As [Delegate], _
ByRef lphRasConn As IntPtr) As
UInt32
End Function
<DllImport("wininet.dll")> _
Public Shared Function InternetDial(ByVal hWndParent As IntPtr, _
<MarshalAs(UnmanagedType.LPTStr)> ByVal pszEntryName As String, _
ByVal dwFlags As Integer, _
ByRef lpdwConnection As
Integer, _
ByVal dwReserved As Integer)
As Integer
End Function
<DllImport("wininet.dll")> _
Public Shared Function
InternetGoOnline(<MarshalAs(UnmanagedType.LPTStr)> ByVal lpszURL As
String, _
ByVal hWndParent As
IntPtr, _
ByVal dwFlags As Integer)
As Boolean
End Function
<DllImport("wininet.dll")> _
Public Shared Function InternetHangUp(ByRef dwConnection As
Integer, _
ByVal dwReserved As Integer)
As Integer
End Function
<DllImport("wininet.dll")> _
Public Shared Function InternetAutoDial(ByVal dwFlags As Integer,
_
ByVal hWndParent As
IntPtr) As Boolean
End Function
<DllImport("wininet.dll")> _
Public Shared Function InternetAutoDialHangup(ByVal dwReserved As
Integer) As Boolean
End Function
<DllImport("wininet.dll")> _
Public Shared Function InternetOpen(ByVal lpszAgent As String, _
ByVal dwAccessType As Integer,
_
ByVal lpszProxyName As String,
_
ByVal lpszProxyBypass As
String, _
ByVal dwFlags As Integer) As
IntPtr
End Function
<DllImport("wininet.dll")> _
Public Shared Function InternetConnect(ByVal hInternet As IntPtr,
_
ByVal lpszServerName As
String, _
ByVal nServerPort As Short,
_
ByVal lpszUserName As
String, _
ByVal lpszPassword As
String, _
ByVal dwService As Integer,
_
ByVal dwFlags As Integer, _
ByVal dwContext As IntPtr)
As IntPtr
End Function
<DllImport("wininet.dll")> _
Public Shared Function InternetGetLastResponseInfo(ByRef errorCode
As Integer, _
ByVal buffer As
System.Text.StringBuilder, _
ByRef
bufferLength As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("wininet.dll")> _
Public Shared Function InternetReadFile(ByVal hFile As IntPtr, _
ByRef lpBuffer As String,
_
ByVal
dwNumberOfBytesToRead As Integer, _
ByRef
lpdwNumberOfBytesRead As Integer) As Boolean
End Function
<DllImport("wininet.dll")> _
Public Shared Function InternetCloseHandle(ByVal hInternet As
IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("wininet.dll")> _
Public Shared Function InternetGetConnectedStateEx(ByVal lpdwFlags
As Integer, _
<MarshalAs(UnmanagedType.LPTStr)> ByVal lpszConnectionName As String,
_
ByVal dwNameLen
As Integer, _
ByVal
dwReserved As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("rasapi32.dll")> _
Public Shared Function RasHangUp(ByVal hRasConn As Integer) As
Integer
End Function
<DllImport("rasapi32.dll")> _
Public Shared Function RasGetErrorString(ByVal uErrorValue As
UInt32, _
ByVal lpszErrorString As
System.Text.StringBuilder, _
<[In]()> ByVal cBufSize
As Integer) As UInt32
End Function
Try those and let me know how it works. If you need further help
please share the code that makes use of these methods.
Thanks,
Seth Rowe