Archive: Is the computer connected


Is the computer connected
Hi,

I didn't find anything like this in the archives, so this is my humble contribution to the NSIS community, a code snippet to determine if the computer is connected through a LAN, by modem or by proxy.

Unfortunately, if the computer is connected to a router, it will still count as a valid connection, even if the router itself isn't connected to the internet. :( Some may still find it useful.

Comments are of course welcome. :)

KenA


What's wrong with the Dialer plug-in?


Originally posted by kichik
What's wrong with the Dialer plug-in?
D'oh ! Nothing at all. It's just me making a fool of myself by re-inventing the wheel. :o

KenA

Originally posted by kichik
What's wrong with the Dialer plug-in?
Dialer plug-in size is 4 kB.

If installer already uses System plug-in, 'pure' script variant decreases package size.

BTW my MSDN says that first parameter is "OUT LPDWORD lpdwFlags", so you can skip it's initialization. Simply:

System::Call 'wininet.dll::InternetGetConnectedState(*i .r11, i 0) .r10'
StrCmp $R0 "0" 0 +2
MessageBox ...
Quit

I use this function:
pardon the text formatting.....

Function InternetConnection
;Check Internet Connection by calling Explorer with the System Plugin

Banner::show /NOUNLOAD /set 76 "Checking for an Internet connection." "Please Wait"

System::Call "wininet::InternetCheckConnection( \
t 'http://www.google.com/', \
i ${FLAG_ICC_FORCE_CONNECTION}, i 0) i .r0"
StrCmp $0 "error" noie3 +1
StrCmp $0 "0" noconnection success


noie3:
Banner::Destroy
MessageBox MB_OK|MB_ICONSTOP "Please Connect the Internet to see the Fonovisa Player."
abort ;Quit ;This will quit the installer. You might want to add your own error handling.

noconnection:
Banner::Destroy
MessageBox MB_OK|MB_ICONSTOP "Please Connect the Internet to see the Fonovisa Player."
abort ;Quit ;This will quit the installer. You might want to add your own error handling.

success:
Banner::Destroy

FunctionEnd


MSDN, InternetCheckConnection: "If lpszUrl is non-NULL, the host value is extracted from it and used to ping that specific host." Some sysadmins just close ICMP (ping) traffic on firewall, so this may not work for a big part of users. And you must be sure that host will answer - this is not constant value too, google may be down or they can turn off ICMP after DOS atack.
So better use your real destination host URL, but this still not gives 100% guarantee.


so what would you recommend?

System::Call 'wininet.dll::InternetGetConnectedState(*i .r11, i 0) .r10'
StrCmp $R0 "0" 0 +2
MessageBox ...
Quit

or

using NSISDL::download with a timeout ?

many thanks


InternetCheckConnection crashed installer on Win98. Is there another way to ping server?


Yep, because wininet.dll is not always available on all os's


From MSDN (about InternetCheckConnection):

Function Information

Windows NT Use version 4.0. Implemented as ANSI and Unicode functions.
Windows Use Windows 95 and later. Implemented as ANSI and Unicode functions.
Header Wininet.h
Import library Wininet.lib
Minimum availability Internet Explorer 3.0 (ANSI only), 5 (ANSI and Unicode)
The same problem: link.

onad
Yep, because wininet.dll is not always available on all os's
This dll came with IE in old Windows versions Minimum availability Internet Explorer 3.0, the only OS without wininet I remember is Win95 Gold :)

What about Windows ME? Can somebody check work of this function on this platform?