|
-
Oct 9th, 2000, 05:46 PM
#1
Thread Starter
Fanatic Member
Can anyone tell me if there's a way to check to see if a dial up connection is already active with VB, and establish one if there isn't? It's for my cheapie browser, and I'm getting lazy in my old age
-
Oct 9th, 2000, 06:16 PM
#2
Detect Internet Connection:
Code:
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
Code
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
Usage
If ActiveConnection = True then
Call MsgBox("You have an active connection.",vbInformation)
Else
Call MsgBox("You have no active connections.", vbInformation)
End If
To establish one:
Code:
Private Const INTERNET_AUTODIAL_FORCE_ONLINE = 1
Private Const INTERNET_AUTODIAL_FORCE_UNATTENDED = 2
Private Declare Function InternetAutodial Lib "wininet.dll" _
(ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Usage
InternetAutodial INTERNET_AUTODIAL_FORCE_UNATTENDED, 0
-
Oct 9th, 2000, 07:02 PM
#3
Thread Starter
Fanatic Member
dialup stuff
Thanks for that big chunk of code there. About the connection establishing thing, how does it know _what_ it's calling though? Or how can I pass it my dialup number before I force it to connect?
-
Oct 9th, 2000, 07:10 PM
#4
If you prefer to dial yourself, here is how:
Code:
Dim X
'"ConnectionsName" is the name under the icon in Dial-up Networking
X = Shell("rundll32.exe rnaui.dll,RnaDial " & "ConnectionsName", 1)
DoEvents
'You can type in your password before the { below.
SendKeys "{enter}", True
DoEvents
-
Oct 9th, 2000, 10:54 PM
#5
Thread Starter
Fanatic Member
dialup stuff
I tried the longer API method to force a connection, but it didn't seem to work. I stuck a thing to activate it in a command button, but when pressed, the hd did some stuff, and just sat there. The other way worked fine though, so I'll use that. What do the INTERNET_AUTODIAL_FORCE_ONLINE and INTERNET_AUTODIAL_FORCE_UNATTENDED constants do? I notice you only used one. The thing to check for a connection worked perfectly. Thanks. BTW, how do you make your VB code in the message look like it was done in the VB environment?
-
Oct 10th, 2000, 06:20 AM
#6
[code]your text[/code]
I will get back to you with the answer to your question (I am in school right now) .
-
Oct 10th, 2000, 02:43 PM
#7
Okay, I'm home right now..until tomorrow at 6:45 AM when skool starts again .
Here is the answer to your question:
INTERNET_AUTODIAL_FORCE_ONLINE = To prompt the user to connect to the Net
INTERNET_AUTODIAL_FORCE_UNATTENDED = To automatically start dialing
Unfortunately, as you said, it doesn't work. I guess the code is crappy, sorry about that.
-
Oct 10th, 2000, 10:54 PM
#8
Thread Starter
Fanatic Member
School is great isn't it? I'm in grad school, so it's not really bad. Anyway, that stuff you mentioned went way over my head. I've never even seen some of that code before, ever. Since you mentioned that WebBrowser event where I can get the address from, I can just set up a keypress that will download something. Thanks.
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
|