|
-
May 11th, 2007, 05:53 AM
#1
Thread Starter
Addicted Member
[2005] How to know the UserName of an internet connection? plz hlp.
Hello
How can I know the username of the active internet connection? (Mostly used for dial-up connections)
Thank you
-
May 11th, 2007, 08:15 PM
#2
Thread Starter
Addicted Member
Re: [2005] How to know the UserName of an internet connection? plz hlp.
hello
Searching MSDN libraries and other forums, I found that I should use "RAS" functions for getting the information of internet connections. Here is some sample codes:
vb Code:
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
But still don't know how to get the "UserName" of a connection. Can someone please help? Or can you at least give me a link to a good guide?
-
May 17th, 2007, 05:14 AM
#3
Thread Starter
Addicted Member
Re: [2005] How to know the UserName of an internet connection? plz hlp.
Hello
Here's a function I could write, which is meant to return the "UserName" of the active internet connection, but it always returns "" (Null).
Can someone please tell me what's wrong with it?
Code:
Public Const RAS_MaxEntryName As Integer = 256
Public Const RAS_MaxDeviceType As Integer = 16
Public Const RAS_MaxDeviceName As Integer = 128
Public Const MAX_PATH As Integer = 260
Public Structure RASCONN
'http://msdn2.microsoft.com/en-us/library/aa376725.aspx
Public dwSize As Int32 'Specifies the size, in bytes, of the RASCONN structure
Public hRasCon As Int32 'Specifies the remote access connection. This handle is used in other remote access API calls
Public szEntryname() As String 'A string that specifies the phone-book entry used to establish the remote access connection. If the connection was established using an empty entry name, this string consists of a PERIOD followed by the connection phone number.
Public szDeviceType() As String 'A null-terminated string that contains the device type through which the connection is made. See RASENTRY for a list of possible device types.
Public szDeviceName() As String 'A null-terminated string that contains the device name through which the connection is made.
Public szPhoneBook() '(As ???) The full path and file name to the phone book containing the entry for this connection
Public dwSubEntry ' (As ???) For multilink connections, specifies the subentry index of one of the connected links. Subentry indices are one based.
End Structure
Public Declare Auto Function RasEnumConnections Lib "rasapi32.dll" _
Alias "RasEnumConnections" ( _
ByRef ipRasConn As RASCONN, _
ByRef ipcb As Integer, _
ByRef ipcConnections As Integer) As Integer
Public Function UserName() As String
Dim unRasConn As New RASCONN
Dim unipcb, unipcConnections As Integer
unRasConn.dwSize = 256
Dim RetVal As Integer = RasEnumConnections(unRasConn, unipcb, unipcConnections)
If RetVal = 0 Then
UserName = unRasConn.szEntryname(0)
Else
UserName = ""
End If
End Function
-
May 19th, 2007, 06:01 AM
#4
Thread Starter
Addicted Member
Re: [2005] How to know the UserName of an internet connection? plz hlp.
-
May 19th, 2007, 08:49 AM
#5
Re: [2005] How to know the UserName of an internet connection? plz hlp.
What is the unipcConnections value that is coming back? From the look of that function call, that returns you the count of connections. If that is 0 then there are no connections.
-
May 19th, 2007, 03:39 PM
#6
Thread Starter
Addicted Member
Re: [2005] How to know the UserName of an internet connection? plz hlp.
I don't know exactly what it is, but I think it's the main cause of my code not to work. Here's what MSDN says about the parameters of RasEnumConnections function:
'http://msdn2.microsoft.com/en-us/library/aa377284.aspx
Parameters
lprasconn
[in, out] Pointer to a buffer that receives, on output, an array of RASCONN structures, one for each RAS connection.
On input, an application must set the dwSize member of the first RASCONN structure in the buffer to sizeof(RASCONN) in order to identify the version of the structure being passed.
lpcb
[in, out] Pointer to a variable that, on input, contains the size, in bytes, of the buffer specified by lprasconn.
On output, the function sets this variable to the number of bytes required to enumerate the RAS connections.
lpcConnections
[out] Pointer to a variable that receives the number of RASCONN structures written to the buffer specified by lprasconn.
Return Value
If the function succeeds, the return value is zero.
If the function fails, the return value is either a nonzero error value listed in the RasError.h header file or ERROR_BUFFER_TOO_SMALL or ERROR_NOT_ENOUGH_MEMORY.
Remarks
If a connection was made without specifying a phone-book entry name, the information returned for that connection gives the connection phone number preceded by ".".
The following sample code enumerates the current RAS connection. This code assumes that, at most, only one connection is currently active. Note that the code sets the dwSize member of the RASCONN structure to specify the version of the structure.
-
May 23rd, 2007, 01:19 PM
#7
Thread Starter
Addicted Member
Re: [2005] How to know the UserName of an internet connection? plz hlp.
Hello again
Is there a component that makes it easy to get some information about internet connections? Such as phone numbers, Usernames, passwords, amount of sent/received data, etc.
Thank you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|