Archive: Function InternetConnect from NSIS Documentation doesn't work!


Function InternetConnect from NSIS Documentation doesn't work!
Hi,

Function InternetConnect from NSIS Documentation doesn't work!

The problem is: the function thinks I am connected to the internet - althought I am definetily not!

Does anybody know a solution (perhaps demonstrated with a short script) how to determine if the user is online - and if he isn't ask him in a loop to do so ?

Cheers,
jago


The documentation doesn't contain any function named InternetConnect. Are you talking about ConnectInternet from the Dialer plug-in's documentation?

That function uses wininet's InternetAttemptConnect. It seems this function settles for an active Ethernet connection and only fires up the dialer, if only a modem is connected to the system. You can find more discussion about this at:

http://groups.google.com/group/micro...19c40bd1692c2e

Checking for an internet connection isn't simple, especially with many connection methods floating around and firewalls that can block your pings. Your best test will be to mimic the actual process you want to perform, in a smaller form. For example, if you want to download a big file from your website, download a very small file from the same server for testing.


Hmmm.
I think the example from the documentation does not take into account that you can have a private IP, and still not be "online" (to the internet).

This is a little big, but it may do the job. Basically, you could check to see if they have one of four types of IPs:

1) a loopback IP (127.0.0.1): not online.
2) no-dhcp ip: 169.254.x.x: not online.
3) a private IP (192.168.x or whatever): maybe online.
4) a normal IP (64.28.x.x): online

So in cases 1 and 2, they are not online. In case 3, they are possibly online - you could try pinging google.com for a reply, maybe. And in case 4, they are online.

It's a little bulky for what you're trying to do, though. Maybe there is a simpler solution.


InternetConnect function fixed
Here is a fixed function for InternetConnect in the Dialer documentation. It is actually better than the example provided because it allows the user to retry to connect. I've attached a script example using it as well.

I used it to program an updater for my software UHARC CMD.
Get it at http://www.pages.drexel.edu/~sag47/uharc

I provide the source with it and it includes a ton of NSIS script examples that can help you write your own software.
SAM

I believe this is what you are looking for.


Function InternetConnect
Start:
; Check for internet Connection
Push $R0
Dialer::GetConnectedState
Pop $R0
StrCmp $R0 "online" connected
MessageBox MB_RETRYCANCEL|MB_TOPMOST|MB_SETFOREGROUND|MB_ICONEXCLAMATION "Can't connect to internet!" idRetry Start
Quit ;Remove to make error not fatal
connected:
Pop $R0
FunctionEnd

Keywords:
Detect internet connection
Detect internet
Detect connection
check for internet connection
check for internet
check for connection
dialer plugin
dialer
dialer internetconnect
dialer internetconnect function
getconnectedstate
dialer::getconnectedstate
nsisdl plugin
nsisdl check internet first