AutoHotkey Community

It is currently May 26th, 2012, 12:18 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: May 22nd, 2006, 8:16 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Quote:
How to find Internet Connection Status ?
http://www.autohotkey.com/forum/viewtopic.php?p=60892#60892

Function ConnectedToInternet( Flag )

Quote:
ConnectedToInternet() should work with all Windows OS.


    0x40 INTERNET_CONNECTION_CONFIGURED - Local system has a valid connection to the Internet, but not be currently connected.
    0x02 INTERNET_CONNECTION_LAN - Local system uses a local area network to connect to the Internet.
    0x01 INTERNET_CONNECTION_MODEM - Local system uses a modem to connect to the Internet.
    0x08 INTERNET_CONNECTION_MODEM_BUSY - No longer used.
    0x20 INTERNET_CONNECTION_OFFLINE - Local system is in offline mode.
    0x04 INTERNET_CONNECTION_PROXY - Local system uses a proxy server to connect to the Internet

    MSDN Reference: List of WinINet Functions

    The Function:
Code:
ConnectedToInternet(flag=0x40) {
Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
}

    Copy-Paste-Try Example:
Code:
If ConnectedToInternet()
   Msgbox, 64, WinInet.dll, ONLINE!
else
   Msgbox, 48, WinInet.dll, OFFLINE!
Return

ConnectedToInternet(flag=0x40) {
Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
}


Credits:
Thanks to Jon for his Post @ How to deal with dllcall returning boolean TRUE/FALSE? ( jordi )
Thanks to Chris for his Post @ the same topic suggesting corrections.



Quote:
Edit : 07-Oct-2006

Here is an another method using an URL to ascertain Internet Connected Status :


Code:
URL := "http://www.autohotkey.com"

If InternetCheckConnection(URL)
   Msgbox, 64, WinInet.dll  [%URL%], Connection Success!
else
   Msgbox, 48, WinInet.dll  [%URL%], Connection Failed!

Return

; The Function

InternetCheckConnection(Url="",FIFC=1) {
Return DllCall("Wininet.dll\InternetCheckConnectionA", Str,Url, Int,FIFC, Int,0)
}


Reference: Request by meter @ Help with Wininet.dll\InternetCheckConnection


_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Last edited by SKAN on October 7th, 2006, 12:04 am, edited 6 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 13th, 2006, 3:16 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
I found an error in your ConnectedToInternet() function. You used:

ConnectedToInternet(flag="") {
If flag=""


The if statement is not an expression so the default value of 0x40 is never set (unless two literal quotation marks were passed). Using ConnectedToInternet(flag = 0x40) would be better.

However I find that calling the function with any of the listed values doesn't work :?

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2006, 8:13 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear Titan, :)

You wrote:
I found an error in your ConnectedToInternet() function. You used:

ConnectedToInternet(flag="") {
If flag=""


The if statement is not an expression so the default value of 0x40 is never set (unless two literal quotation marks were passed). Using ConnectedToInternet(flag = 0x40) would be better.


:shock: :shock:
Thanks for pointing it.

You wrote:
However I find that calling the function with any of the listed values doesn't work


Have updated ConnectedToInternet(). Please try again and let me know. It works now properly with my Single user PC with ADSL connection.

Regards, :)


Last edited by SKAN on June 16th, 2008, 7:34 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 15th, 2006, 10:35 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Goyyah wrote:
Have updated ConnectedToInternet(). Please try again and let me know. It works now properly with my Single user PC with ASDL connection.

No it doesn't work for me :?
This version seems to work:
Code:
MsgBox % Connected()

Connected(fl = 0x40) {
   Return, DllCall("Wininet.dll\InternetGetConnectedState", "UInt *", fl, "UInt", 0)
}

However the flags seem to be ignored which is quite strange.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2006, 6:29 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear Titan, :)

You wrote:
This version seems to work:
Code:
MsgBox % Connected()

Connected(fl = 0x40) {
   Return, DllCall("Wininet.dll\InternetGetConnectedState", "UInt *", fl, "UInt", 0)
}

However the flags seem to be ignored which is quite strange.


:roll: Yes! This version works for me.. I am too confused! :roll:

Regards, :)


Last edited by SKAN on June 16th, 2008, 7:34 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 6th, 2006, 11:54 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Quote:
The following post has been updated:
Quote:
Added example: Wininet.dll\InternetCheckConnection

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 6th, 2006, 11:59 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Goyyah wrote:
Code:
ConnectedToInternet(flag="") {
If flag=
   flag=0x40

Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
}


Since 0x40 is a literal integer you can simplify it to:
Code:
ConnectedToInternet(flag = 0x40) {
   Return, DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag, "Int", 0)
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 7th, 2006, 12:06 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Titan wrote:
Since 0x40 is a literal integer you can simplify it


Thanks! :D .. Done!

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Help!!
PostPosted: September 14th, 2008, 6:56 am 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
I would greatly appreciate help on these two functions..

The first one gives the same result on using any of the given flags.

The second one makes my program unresponsive till the function returns, but otherwise works well.

Could you tell me how to ?? isolate that thread (or do something better ;-) )

Thanks for your response.





SKAN wrote:
Quote:
How to find Internet Connection Status ?
http://www.autohotkey.com/forum/viewtopic.php?p=60892#60892

Function ConnectedToInternet( Flag )

Quote:
ConnectedToInternet() should work with all Windows OS.


    0x40 INTERNET_CONNECTION_CONFIGURED - Local system has a valid connection to the Internet, but not be currently connected.
    0x02 INTERNET_CONNECTION_LAN - Local system uses a local area network to connect to the Internet.
    0x01 INTERNET_CONNECTION_MODEM - Local system uses a modem to connect to the Internet.
    0x08 INTERNET_CONNECTION_MODEM_BUSY - No longer used.
    0x20 INTERNET_CONNECTION_OFFLINE - Local system is in offline mode.
    0x04 INTERNET_CONNECTION_PROXY - Local system uses a proxy server to connect to the Internet

    MSDN Reference: List of WinINet Functions

    The Function:
Code:
ConnectedToInternet(flag=0x40) {
Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
}

    Copy-Paste-Try Example:
Code:
If ConnectedToInternet()
   Msgbox, 64, WinInet.dll, ONLINE!
else
   Msgbox, 48, WinInet.dll, OFFLINE!
Return

ConnectedToInternet(flag=0x40) {
Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
}


Credits:
Thanks to Jon for his Post @ How to deal with dllcall returning boolean TRUE/FALSE? ( jordi )
Thanks to Chris for his Post @ the same topic suggesting corrections.



Quote:
Edit : 07-Oct-2006

Here is an another method using an URL to ascertain Internet Connected Status :


Code:
URL := "http://www.autohotkey.com"

If InternetCheckConnection(URL)
   Msgbox, 64, WinInet.dll  [%URL%], Connection Success!
else
   Msgbox, 48, WinInet.dll  [%URL%], Connection Failed!

Return

; The Function

InternetCheckConnection(Url="",FIFC=1) {
Return DllCall("Wininet.dll\InternetCheckConnectionA", Str,Url, Int,FIFC, Int,0)
}


Reference: Request by meter @ Help with Wininet.dll\InternetCheckConnection



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2008, 7:44 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
There are two more options for you to try: IsDestinationReachable() and Ping :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thanks
PostPosted: September 14th, 2008, 8:11 am 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
SKAN wrote:
There are two more options for you to try: IsDestinationReachable() and Ping :)


Thanks SKAN very much!!
But the first one has the same problem i stated ( it makes my script unresponsive for the time of the call), please try to right click the taskbar icon while the call is in progress (upto 19 secs sometimes)

The second option just gives me unreachable inspite of being online! Am i doing something wrong (i even changed the URL to google.com)

Thanks again!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Thanks
PostPosted: September 14th, 2008, 8:21 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
shajul wrote:
The second option just gives me unreachable inspite of being online! Am i doing something wrong (i even changed the URL to google.com)


Code:
url=www.google.com
RunWait, ping.exe %url% -n 1,, Hide UseErrorlevel
If Errorlevel
     MsgBox,16,%url%, Destination Unreachable
Else MsgBox,64,%url%, Destination Reachable


For me, the above has been the most reliable and works for me in all OS.
Are you sure your firewall is not blocking ping.exe ? BTW, What is your OS ?

:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thanks again!
PostPosted: September 14th, 2008, 8:48 am 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
Sorry SKAN, now it works..
i checked it on the command line, the problem is the response is slow, so it times out before the response and returns an Errorlevel..
It is totally cause i am using BSNL EVDO!! It is supposed to be wireless broadband, but it is slower than dial-up :oops:

I have a broadband at my home, so will test it when i get back..

Thanks again!

_________________
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group