WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

DialUp Networking (DUN) Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Check Existence of Dun Connection

Keywords:     HKEY_DYN_DATA   DUN Connection

Question:

How can I check the existence of a DUN Connection? I am trying to create a routine which checks the existence of a dial up connection and if found (connected that is), disconnects it.

Answer:

The DUN functions in WinBatch work the opposite way. If you don't already have a connection, it will make one for you.

The dunConnect is supposed to check to see if the connection is already open, and if so, return the handle to the open connection. Make sure the names in the dunConnect matches the name of the connection you are trying to test.

It should not try to open a new connection unless the names are different and you have more than one modem.

I think by poking around in the HKEY_DYN_DATA section of the registry, you *might* be able to figure out if you have a DUN connection. Or try the DllCall method below.

Also, if you can get a pComOpen to work, it would indicate that dialup networking is not active at that moment. You could then close the port and terminate the program. The serial extender needs access to the com port, and if it is tied up with dialup networking, then pComOpen will not work. So you can use this information to indicate that a DUN connection still exists.

If you're trying to determine when to close a connection, with the Internet extender you should be able to see bytes going by. If there is no traffic for maybe 30 seconds, it might be time to close the connection.

The code might look something like:

AddExtender("wwwsk34I.dll")
con=dunConnect("connection name")   ; YOUR CONNECTION APPLET

if con==0
    Message("Error","Zero con returned")
    exit
endif

OldBytesIn=wxGetInfo(4,con)

while 1
   TimeDelay(30)
   NewBytesIn=wxGetInfo(4,con)
   if NewBytesIn==OldBytesIn then break
   OldBytesIn=NewBytesIn
endwhile

dunDisconnect(con)
Display(5,"Lurker","Disconnected")
exit

Question:

I'm trying to figure out how to use dllcall stuff to find out if a DUN connection is going on.

According to the API info, the WININET.dll can find out if there is a DUN connection going on or not. The "InternetGetConnectedState" will return a true if connected and false if not. So this is what I did.

	dllhandle=DllLoad("%winsys%wininet.dll")
	a = DllCall(dllhandle, long:"InternetGetConnectedState", lpnull:"")
	DllFree(dllhandle)
	pause("", "%a%")
and this is what happened I get what looks like a wil message box that the title says INTERNAL DYNALLOC ERROR and the text states Tag overwrite 1 The only way to exit that message or the wbt is to shut it down w/taskmanager. So now that I'm twice as lost as before, any Ideas?

Answer:

Hmmm... Here's the WININET.DLL info. This is the similar code to what is used in the WinInet extender's iGetConState function.
	BOOL InternetGetConnectedState(
	OUT LPDWORD lpdwFlags,
	IN DWORD dwReserved
	);
Your DLLCall should be more like:
	dadll=strcat(DirWindows(1),"wininet.dll")
        binbuf=BinaryAlloc(4)
        BinaryEODset(binbuf,4)

        rslt=DllCall(dadll, long:"InternetGetConnectedState", lpbinary:binbuf,long:0)
        debug(1)
        code=BinaryPeek4(binbuf,0)
        BinaryFree(binbuf)
        if rslt==@True
        switch code
           case 1
                str="INTERNET_CONNECTION_MODEM... Local system uses a modem to connect to the Internet."
                break
           case 2
                str="INTERNET_CONNECTION_LAN... Local system uses a local area network to connect to the Internet."
                break
           case 4
                str="INTERNET_CONNECTION_PROXY... Local system uses a proxy server to connect to the Internet."
                break
           case 8
                str="INTERNET_CONNECTION_MODEM_BUSY...  Local system's modem is busy with a non-Internet connection."
                break
        endswitch
        message("How is the user connected?",str)
        else
                message("No connection","User is not connected to internet")
        endif

;return values from InternetGetConnectedState could be

  • 1 INTERNET_CONNECTION_MODEM Local system uses a modem to connect to the Internet.
  • 2 INTERNET_CONNECTION_LAN Local system uses a local area network to connect to the Internet.
  • 4 INTERNET_CONNECTION_PROXY Local system uses a proxy server to connect to the Internet.
  • 8 INTERNET_CONNECTION_MODEM_BUSY Local system's modem is busy with a non-Internet connection.
See also: WinInet Extender functions iGetConState( request) and iGetConStatEx( request) {*IE5} which can get the connected state of the local system. Use these functions instead of the DllCall....
Article ID:   W12621
Filename:   Check Existence of a DUN Connection.txt
File Created: 2001:03:01:15:12:56
Last Updated: 2001:03:01:15:12:56