Hello.
I have a question regarding checking internet connection.
I am trying to detect if there is an internet connection with the folowing code:
------------------------------------
Function ConnectInternet
Push $R0
ClearErrors
Dialer::AttemptConnect
IfErrors noie3
Pop $R0
StrCmp $R0 "online" connected
MessageBox MB_OK|MB_ICONSTOP "Cannot connect to the internet."
Quit
noie3:
; IE3 not installed
MessageBox MB_OK|MB_ICONINFORMATION "Please connect to the internet now."
connected:
MessageBox MB_OK " connection to internet was verified."
Pop $R0
FunctionEnd
-----------------------
The problem is : I want to detect if
the function works corectly and I unplug the network
cable. Then I run the installer, but the function still detects that the internet connection is on, and I get the message box with "connection to internet was verified"
How do I solve this?
Thanks.
check internet connection
19 posts
Are you sure that you have the correct sintax of the plugin?
Maybe it will always report online when there is a permanent network connection. Try it on a system with dial-up access.
i can confirm what joost said
Most likely, the cause for this behavior is that the macro relies on the InternetGetconnectionState(Ex)() API in WININET.DLL which ships with IE. As you've seen, this API is _not_ reliable (just unplug the cable on a host that connects through a router...)
After searching more, I think the least bad solution is to connect out to some IP address that you hard-coded... but that won't do you any good if the client host is running a firewall which prevents any unauthorized outgoing connections. Rats :-)
Fred.
After searching more, I think the least bad solution is to connect out to some IP address that you hard-coded... but that won't do you any good if the client host is running a firewall which prevents any unauthorized outgoing connections. Rats :-)
Fred.
hi guys
i have a problem with all codes check internet connected!
please see this picture:

if my internet disable or have a problem from my internet service providers Again this codes show you're internet is connected! In the event that my internet have problem!
Is there any way :
01-when the Internet not connected then show massage: internet not connected
02-when internet connected then show massage: internet is connected
03-when internet is connect BUT internet have a problem show massage: internet connected but have a problem! OR show massage not internet access!
how can do it?
thanks
i have a problem with all codes check internet connected!
please see this picture:

if my internet disable or have a problem from my internet service providers Again this codes show you're internet is connected! In the event that my internet have problem!
Is there any way :
01-when the Internet not connected then show massage: internet not connected
02-when internet connected then show massage: internet is connected
03-when internet is connect BUT internet have a problem show massage: internet connected but have a problem! OR show massage not internet access!
how can do it?
thanks
The only way to know is to try to connect somewhere and even then you don't know for sure if there is a firewall blocking things or a connection problem.
thanksOriginally Posted by Anders View PostThe only way to know is to try to connect somewhere and even then you don't know for sure if there is a firewall blocking things or a connection problem.
In your opinion What is Best Code To do this?
If you are downloading a file during setup then inetc (or whatever download plugin you are using) will handle the error...
Some time ago I also had this problem. Based on all information that I found in Internet I made a lot of tests. At the end I made a macro like this:
;*******************************************************************************
;* Unit name: CheckInternetConnection *
;*******************************************************************************
;* Description: Check if Internet connection is established *
;*******************************************************************************
;* Usage: *
;* ${CheckInternetConnection} "http://www.google.com/" $0 *
;* ${If} $0 == "OK" *
;* MessageBox MB_OK "Connection established!" *
;* ${Else} *
;* MessageBox MB_OK "No connection!" *
;* ${EndIf} *
;*******************************************************************************
!include "Util.nsh"
!macro CheckInternetConnectionCall _URL _RESULT
!verbose push
Push `${_URL}`
${CallArtificialFunction} CheckInternetConnection_
Pop `${_RESULT}`
!verbose pop
!macroend
!define CheckInternetConnection `!insertmacro CheckInternetConnectionCall`
!define un.CheckInternetConnection `!insertmacro CheckInternetConnectionCall`
!macro CheckInternetConnection
!macroend
!macro un.CheckInternetConnection
!macroend
!define FLAG_ICC_FORCE_CONNECTION 1
!macro CheckInternetConnection_
!verbose push
Exch $0
System::Call "wininet::InternetCheckConnection(t '$0', i ${FLAG_ICC_FORCE_CONNECTION}, i 0) i .r0"
${If} $0 == 1
StrCpy $0 "OK"
${Else}
StrCpy $0 "FAILED"
${EndIf}
Exch $0
!verbose pop
!macroend
;******************************************************************************* Up to now I couldn't find problems with it, but as Anders said, probably there are some exceptions.Originally Posted by TrifonovS View PostSome time ago I also had this problem. Based on all information that I found in Internet I made a lot of tests. At the end I made a macro like this:
...
Up to now I couldn't find problems with it, but as Anders said, probably there are some exceptions.
thanks mr TrifonovS
i tested you're code this code is a best code for check internet connected or not connected.
but if change a small part of code is better!
i change:
Ip Address: 1.1.1.1
and run this code exe file ,program say not connected!
i open google.com with firefox and google open and i see this!
then i change "http://www.google.com/" To "https://www.google.com/" then i see program good worked!
It say this perhaps this status remove one of some exceptions:
thanks for help 🙂
Section
${CheckInternetConnection} "https://www.google.com/" $0
${If} $0 == "OK"
MessageBox MB_OK "You Are Online Now"
${ElseIf} $0 == "FAILED"
MessageBox MB_OK "You Are Offline Now"
${Else}
MessageBox MB_OK "Find A Error!"
${EndIf}
SectionEnd Hi r2du-soft!
Thanks for the feedback. I think that the usage of http or https protocol depends from the site. For Google - you are right. As far as I know they support only https. But for other sites this may not work. Actually in my code I don't try to access to Google's site. This was written only as an example and I'm not sure that I have tested it...
Thanks for the feedback. I think that the usage of http or https protocol depends from the site. For Google - you are right. As far as I know they support only https. But for other sites this may not work. Actually in my code I don't try to access to Google's site. This was written only as an example and I'm not sure that I have tested it...
What?Originally Posted by TrifonovS View PostAs far as I know they support only https.
curl -vv "http://www.google.com/"Anyway, you should try more than one host. Google+Yahoo+Microsoft or something like that.
* Connected to www.google.com (173.194.40.243) port 80 (#0)
> GET / HTTP/1.1
...
>
< HTTP/1.1 302 Found
...
hi my friendOriginally Posted by TrifonovS View PostHi r2du-soft!
Thanks for the feedback. I think that the usage of http or https protocol depends from the site. For Google - you are right. As far as I know they support only https. But for other sites this may not work. Actually in my code I don't try to access to Google's site. This was written only as an example and I'm not sure that I have tested it...
yes i tested this Several times and when firefox open google but program say not connected!
but i tested now say connected! i do not know why sometimes with http say connected or sometimes say notconnected!
yes more google services run at https .
i understand this is a example and you're example is a best example 🙂
Because google service always connected but other sites service is possible offlined.
thanks
+
Anders saying true
the best way is checking several big service for trust greater
but i think all service use from https!
Firefox opens the Google's site even if you type "http:\\www.google.com", because if you look carefully, you will see that it automatically corrects the link to "https:\\www.google.com" (I don't know how this works). But the macro that I made has no such possibility and the protocol stays wrong. Therefore the connection can not be established.
MSDN does not specify how InternetCheckConnection works, and it even says you can use NULL as the URL. If it is only connecting with a TCP socket then http:\\www.google.com will work. Even if it wants a HTTP server it should work because http:\\www.google.com just returns a valid 302 redirect...
I try to use this code to detect if internet connection is available but I got error :
' Invalid command ${CallArtificialFunction} '
' Invalid command ${CallArtificialFunction} '
This is a problem you should be able to fix on your own; It probably worked for somebody else so we can assume they included some header that you did not. Your first step should be to check if CallArtificialFunction exists in one of the files in NSIS\Include...Originally Posted by mrjohn View PostI try to use this code to detect if internet connection is available but I got error :
' Invalid command ${CallArtificialFunction} '
Indeead,thanks!