InternetAutodialHangup & Win98 will not auto hang-up.

I have a small dial-up program for my weather station that was working fine on my Win95 & WinNT machines. I upgraded the Win95 to 98. (stupid me) Now it will not hang-up automatically. I can hang up manually. I had to set the dialup dialog to disconnect in 3 minutes. (that's the minimum it can be set) So now it just sits there until it times out, does a count down from 30 seconds and then disconnects. That is not how I want it to work. Is there a setting I missed? Do I need to edit the registry? Do I now own an expensive boat anchor? ;>)

Here's a snippet of source.

Private Declare Function InternetAutodialHangup Lib "wininet.dll" (ByVal dwReserved As Long) As Long

If lngConnection <> 0 Then InternetCloseHandle (lngConnection)
If lngOpen <> 0 Then InternetCloseHandle (lngOpen)
lngConnection = 0
lngOpen = 0
   
Call InternetAutodialHangup(0)

Thanks in advance,
Clyde
LVL 1
cbasic100798Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
cantrellConnect With a Mentor Commented:
I checked and somewhere along the line, I must have added 'option explicit' because it is at the top of my module. I am going to paste the entire thing, some of which you may not need, but here is everything I have... Let me know if you have problems with this...

-- module code ---

Option Explicit
Dim keyhandle As Long


Public Function Connected_To_ISP() As Boolean

If ConfigureForm.chkDetect.Value = 0 Then Connected_To_ISP = True: Exit Function

If MAILERROR Then Exit Function


    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
    Connected_To_ISP = False
    lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
    ReturnCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0, KEY_ALL_ACCESS, 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
                '     ' Not Connected
            Else
                '     ' Connected
                Connected_To_ISP = True
            End If

            End If

                RegCloseKey (Hkey)
            End If

End Function


' 2) Once I determine that I'd like to disconnect, How do I do
'    that? It seems like I need some interface to DUN to do it.
'    Use RasHangUp. In this example I display a splash screen (frmHangupSplash)
'    while the hangup is in progress. You'll want to set gstrISPName =
'    Get_ISP_Name() before calling HangUp(), or better yet modify HangUP and
'    pass the DUN connection name (the ISP) as a parameter..

Public Sub HangUp(ISPName)

    Dim i As Long
    Dim lpRasConn(255) As RasConn
    Dim lpcb As Long
    Dim lpcConnections As Long
    Dim hRasConn As Long
                                                            'frmHangupSplash.Show
                                                            'frmHangupSplash.Refresh
    lpRasConn(0).dwSize = RAS_RASCONNSIZE
    lpcb = RAS_MAXENTRYNAME * lpRasConn(0).dwSize
    lpcConnections = 0
    ReturnCode = RasEnumConnections(lpRasConn(0), lpcb, lpcConnections)
    '     ' Drop ALL the connections that match the currect
    '     ' connections name.

    If ReturnCode = ERROR_SUCCESS Then

        For i = 0 To lpcConnections - 1

            If Trim$(ByteToString(lpRasConn(i).szEntryName)) = Trim$(ISPName) Then
                hRasConn = lpRasConn(i).hRasConn
                ReturnCode = RasHangUp(ByVal hRasConn)
            End If

            Next i

            End If

                ' It takes about 3 seconds to drop the connection.
                                                                        '
                'Wait (3)
If MAILERROR Then Exit Sub

                While Connected_To_ISP
                '    Wait (1)
                  DoEvents
                Wend

                   ' Unload frmHangupSplash
            End Sub

Public Sub Wait(sngSeconds As Single)

    Dim sngEndTime As Single
    sngEndTime = Timer + sngSeconds

    While Timer < sngEndTime

        DoEvents
        Wend

    End Sub


'*************************************************
'     **************************
'     ' Name: ByteToString
' ' Description:* * * THIS IS A FOLLOWUP SUBMISSION * * *
'Purpose: Convert a string in byte format (usually from a DLL call) to a string of text.
'PLEASE POST THIS AS A FOLLOWUP OR ADD TO THE CODE SAMPLE TITLED "Detect if there is a Dial up network connection" attributed to me J Gerard Olszowiec, entity@ns.sympatico.ca. The newsgroup post that you captured had a followup post that included the ByteToString code. I've been receiving requets for this functions code. Much Thanx. - Gerard
'**************************

Public Function ByteToString(bytString() As Byte) As String

     ' ' Convert a string in byte format (usually from
    '      a DLL call)
    '      ' ' to a string of text.
     Dim i As Integer
     ByteToString = ""
     i = 0

    While bytString(i)
         ByteToString = ByteToString & Chr$(bytString(i))
         i = i + 1
    Wend

    End Function

Private Sub cmdHangup_Click()

HangUp (Get_ISP_Name)

End Sub

Private Sub Command1_Click()

    Dim X As Long
   
    X = Shell("rundll32.exe rnaui.dll,RnaDial " & Text2, 1)

   ' DoEvents
   '     SendKeys "{enter}", True

   '     DoEvents
    End Sub

Private Sub Form_Load()

Text2 = Get_ISP_Name

Text1 = Connected_To_ISP

Command1.Caption = "Connect to " + Text2

End Sub

Public Function Get_ISP_Name() As String

    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 String
    Dim lpcbData As Long
    Get_ISP_Name = ""

  '  If Connected_To_ISP Then
        lpSubKey = "RemoteAccess"
        ReturnCode = RegOpenKeyEx(HKEY_CURRENT_USER, lpSubKey, 0, KEY_ALL_ACCESS, phkResult)
       
            If ReturnCode = ERROR_SUCCESS Then
            Hkey = phkResult
            lpValueName = "Default"
            lpReserved = APINULL
            lpType = APINULL
            lpData = APINULL
            lpcbData = APINULL
            ReturnCode = RegQueryValueEx(Hkey, lpValueName, lpReserved, lpType, ByVal lpData, lpcbData)
            lpData = String$(lpcbData, 0)
            ReturnCode = RegQueryValueEx(Hkey, lpValueName, lpReserved, lpType, ByVal lpData, lpcbData)

            If ReturnCode = ERROR_SUCCESS Then Get_ISP_Name = Left$(lpData, lpcbData - 1)
           
            RegCloseKey (Hkey)
        End If

 '     End If
 
'if we don't have a popserver listed already, see if we can find one in the registry.
'this is most helpful for new users.
 'If Len(ConfigureForm.txtPOPserver) = 0 Then
 
  If Len(Get_ISP_Name) = 0 Then Get_ISP_Name = "NO DEFAULT ISP DETECTED!"

End Function



0
 
cantrellCommented:
Get your isp name that your connected to from the registry, then hang it up via the code below... (just paste it into a module and run:)

'whenever you want to hang up.
HangUp (Get_ISP_Name)


'---paste into module---
Public Function Connected_To_ISP() 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
    Connected_To_ISP = False
    lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
    ReturnCode = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, phkResult)

    If ReturnCode = 0 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
                '     ' Not Connected
            Else
                '     ' Connected
                Connected_To_ISP = True
            End If

            End If

                RegCloseKey (Hkey)
            End If

End Function


' 2) Once I determine that I'd like to disconnect, How do I do
'    that? It seems like I need some interface to DUN to do it.
'    Use RasHangUp. In this example I display a splash screen (frmHangupSplash)
'    while the hangup is in progress. You'll want to set gstrISPName =
'    Get_ISP_Name() before calling HangUp(), or better yet modify HangUP and
'    pass the DUN connection name (the ISP) as a parameter..

Public Sub HangUp(ISPName)

    Dim i As Long
    Dim lpRasConn(255) As RasConn
    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)
    '     ' Drop ALL the connections that match the currect
    '     ' connections name.

    If ReturnCode = ERROR_SUCCESS Then

        For i = 0 To lpcConnections - 1

            If Trim$(ByteToString(lpRasConn(i).szEntryName)) = Trim$(ISPName) Then
                hRasConn = lpRasConn(i).hRasConn
                ReturnCode = RasHangUp(ByVal hRasConn)
            End If

            Next i

            End If

                ' It takes about 3 seconds to drop the connection.
                                                       While Connected_To_ISP
                  DoEvents
                Wend

End Sub


'**********
'     **************************
'     ' Name: ByteToString
'**************************

Public Function ByteToString(bytString() As Byte) As String

     ' ' Convert a string in byte format (usually from
    '      a DLL call)
    '      ' ' to a string of text.
     Dim i As Integer
     ByteToString = ""
     i = 0

    While bytString(i)
         ByteToString = ByteToString & Chr$(bytString(i))
         i = i + 1
    Wend

    End Function



Public Function Get_ISP_Name() As String

    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 String
    Dim lpcbData As Long
    Get_ISP_Name = ""

  '  If Connected_To_ISP Then
        lpSubKey = "RemoteAccess"
        ReturnCode = RegOpenKey(HKEY_CURRENT_USER, lpSubKey, phkResult)

        If ReturnCode = ERROR_SUCCESS Then
            Hkey = phkResult
            lpValueName = "Default"
            lpReserved = APINULL
            lpType = APINULL
            lpData = APINULL
            lpcbData = APINULL
            ReturnCode = RegQueryValueEx(Hkey, lpValueName, lpReserved, lpType, ByVal lpData, lpcbData)
            lpData = String$(lpcbData, 0)
       ReturnCode = RegQueryValueEx(Hkey, lpValueName, lpReserved, lpType, ByVal lpData, lpcbData)

            If ReturnCode = ERROR_SUCCESS Then Get_ISP_Name = Left$(lpData, lpcbData - 1)
           
            RegCloseKey (Hkey)
        End If

 '     End If
 
 

End Function


0
 
cbasic100798Author Commented:
cantrell,
Thanks for your quick response BUT I want to use my program as I have for the past 3 years. Why doesn't the autohangup function work the same with Win98? Please leave this Q open so I can get a few comments from the Experts and then decide which one best suits my situation.

Thank you,
Clyde
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
cantrellCommented:
I don't know, but this is what I'm using for windows 98 and it works perfectly.
0
 
cbasic100798Author Commented:
Thank you cantrell,
I will give it a shot and get back to you. My program is meant to be running in the background posting the weather report hourly and sending an email notification once a day & logging off  without ANY user interaction.

Clyde
0
 
cantrellCommented:
this doesn't require any user interaction. As long as you have the code somewhere, just use : HangUp (Get_ISP_Name)  whenever you want to hang up the internet connection, and it just hangs it up - no user interaction.
0
 
cbasic100798Author Commented:
cantrell,
*RegOpenKey* function is provided only for compatibility with 16-bit versions of Windows. *RegOpenKeyEx* is the function that is now used.

I always declare *Option Explicit* and I'm getting a lot of *Variable not defined* message for the *APENULL* & *HKEY_LOCAL_MACHINE* & *HKEY_CURRENT_USER* variables & others.

Suggestions?

BTW, this program will be running on WinNT & Win95-98.

Thanks,
Clyde
0
 
cantrellCommented:
Here is some more info, with the regopenkeyex

---------------------------
'Security Mask constants
Public Const READ_CONTROL = &H20000
Public Const SYNCHRONIZE = &H100000
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const STANDARD_RIGHTS_READ = READ_CONTROL
Public Const STANDARD_RIGHTS_WRITE = READ_CONTROL
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_CREATE_LINK = &H20
Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Public Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))

Public Const HKEY_LOCAL_MACHINE = &H80000002

Public Const APINULL = 0&


'new getispname with the regopenkeyex
Public Function Get_ISP_Name() As String

    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 String
    Dim lpcbData As Long
    Get_ISP_Name = ""

  '  If Connected_To_ISP Then
        lpSubKey = "RemoteAccess"
        ReturnCode = RegOpenKeyEx(HKEY_CURRENT_USER, lpSubKey, 0, KEY_ALL_ACCESS, phkResult)
       
            If ReturnCode = ERROR_SUCCESS Then
            Hkey = phkResult
            lpValueName = "Default"
            lpReserved = APINULL
            lpType = APINULL
            lpData = APINULL
            lpcbData = APINULL
            ReturnCode = RegQueryValueEx(Hkey, lpValueName, lpReserved, lpType, ByVal lpData, lpcbData)
            lpData = String$(lpcbData, 0)
            ReturnCode = RegQueryValueEx(Hkey, lpValueName, lpReserved, lpType, ByVal lpData, lpcbData)

            If ReturnCode = ERROR_SUCCESS Then Get_ISP_Name = Left$(lpData, lpcbData - 1)
           
            RegCloseKey (Hkey)
        End If

 '     End If
 
'if we don't have a popserver listed already, see if we can find one in the registry.
'this is most helpful for new users.
 'If Len(ConfigureForm.txtPOPserver) = 0 Then  

End Function

'New connected_to_isp with regopenkeyex
Public Function Connected_To_ISP() As Boolean

If ConfigureForm.chkDetect.Value = 0 Then Connected_To_ISP = True: Exit Function

If MAILERROR Then Exit Function


    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
    Connected_To_ISP = False
    lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
    ReturnCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, phkResult, KEY_ALL_ACCESS, keyhandle)
   

    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
                '     ' Not Connected
            Else
                '     ' Connected
                Connected_To_ISP = True
            End If

            End If

                RegCloseKey (Hkey)
            End If

End Function
0
 
cbasic100798Author Commented:
Cantrell,
I'm still getting a "variable not defined" message for the RegOpenKeyEx function. Did you miss something else?


Clyde
0
 
cbasic100798Author Commented:
Cantrell,Anything yet?
I still need help.
Clyde
0
 
cantrellCommented:
what variable does it say is "undefined"? If it's "ERROR_SUCCESS" just replace it with a 0 (that's zero), or you can do PUBLIC CONST ERROR_SUCCESS = 0 if you want.
0
 
cbasic100798Author Commented:
Cantrell,
I'm still getting a "variable not defined" message for the ***RegOpenKeyEx*** function. Did you miss something else?

Clyde


0
 
cantrellCommented:
Ummm, just the most important thing - the function declaration :)
Here it is:

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal Hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, ByRef phkResult As Long) As Long
0
 
cbasic100798Author Commented:
cantrell,
I have a feeling the other function declarations are missing also. ***RegQueryValueEx*** ***RegCloseKey***

I'll work on it this weekend and get back to you.

Thanks for your help,
Clyde
0
 
cantrellCommented:
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal Hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, ByRef phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
0
 
cbasic100798Author Commented:
Cantrell,
Do you normally define your variables?
Please put *Option Explicit* in your declarations and you will see what I mean. In the *Get_ISP_Name* function take a look at the *ReturnCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, phkResult, KEY_ALL_ACCESS, keyhandle)* call, ReturnCode is not defined, the 3rd variable is a reserved argument, keyhandle is not defined. In the *HangUp* function *RasConn* user type is not defined. *HKEY_CURRENT_USER* not defined. PLEASE, PLEASE test your code, debug your code, THEN post your code. I'll gladly increase the points once I have a solution.

Thanks
Clyde
0
 
cbasic100798Author Commented:
Cantrell,
Did you give up on me?
0
 
cantrellCommented:
No I didn't... Sorry, what I put above works if you remove the 'option explicit'. Otherwise, if you want 'Option Explicit' all you have to do is go down and replace the variables with definitions. It's just time consuming and I don't believe really necessary yet, since over 60,000 people are using this exact same code and it's never had a problem.

I will look into adding option explicit.
0
 
cbasic100798Author Commented:
Thanks Cantrell,
I'll check it out and get back to you.
Clyde
0
 
cbasic100798Author Commented:
Cantrell,
I can't get your code to work. I did a little research on my end, re-installed a few files and now the InternetAutoDialHangup function works fine.

Thanks for your efforts,

Clyde
0
All Courses

From novice to tech pro — start learning today.