- NSIS Discussion
- Is the computer connected
Archive: Is the computer connected
KenA
11th October 2004 17:19 UTC
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
kichik
11th October 2004 17:21 UTC
What's wrong with the Dialer plug-in?
KenA
11th October 2004 17:32 UTC
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
Takhir
12th October 2004 09:30 UTC
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
grahama
14th October 2004 00:46 UTC
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
Takhir
14th October 2004 13:07 UTC
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.
grahama
14th October 2004 22:27 UTC
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
glory_man
28th June 2005 13:10 UTC
InternetCheckConnection crashed installer on Win98. Is there another way to ping server?
onad
28th June 2005 13:37 UTC
Yep, because wininet.dll is not always available on all os's
glory_man
28th June 2005 14:42 UTC
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.
Takhir
28th June 2005 15:28 UTC
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 :)
glory_man
12th July 2005 16:42 UTC
What about Windows ME? Can somebody check work of this function on this platform?