Jump to content

To check if the user has an active inet connection


Recommended Posts

...without having the script that is making the check hose.

Currently, I'm writting a script that is doing version checking against a file I host off my server. Problem is that if the user running the program is not connected as in modem or bad DSL connection (me being the latter as of late), the AutoIT app seems to lock (waiting for a timeout perhaps).

Is there a way that will *quickly* tell if the computer has a live inet connection?

TIA

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

Use the ping command and ping a host... If @error appears, you are offline, if not, online... Maybe there is a proccess what starts with the connection, maybe you can check it... Dunno any other way.

Edited by Baku
Link to comment
Share on other sites

;--------------------------------------------------------------------------------------------
;check $ret[0] for trueness, and $ret[1] for type of connection according to variables provided...
;--------------------------------------------------------------------------------------------
$INTERNET_CONNECTION_MODEM        = 0x1
$INTERNET_CONNECTION_LAN            = 0x2
$INTERNET_CONNECTION_PROXY        = 0x4
$INTERNET_CONNECTION_MODEM_BUSY  = 0x8
$INTERNET_RAS_INSTALLED          = 0x10
$INTERNET_CONNECTION_OFFLINE        = 0x20
$INTERNET_CONNECTION_CONFIGURED  = 0x40

    $ret = DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0)

    If $ret[0] then
      ;check type of connection
        $sX = ""
        If BitAND($ret[1], $INTERNET_CONNECTION_MODEM)    Then $sX = $sX & "MODEM" & @LF
        If BitAND($ret[1], $INTERNET_CONNECTION_LAN)        Then $sX = $sX & "LAN" & @LF
        If BitAND($ret[1], $INTERNET_CONNECTION_PROXY)    Then $sX = $sX & "PROXY" & @LF
        If BitAND($ret[1], $INTERNET_CONNECTION_MODEM_BUSY) Then $sX = $sX & "MODEM_BUSY" & @LF
        If BitAND($ret[1], $INTERNET_RAS_INSTALLED)      Then $sX = $sX & "RAS_INSTALLED" & @LF
        If BitAND($ret[1], $INTERNET_CONNECTION_OFFLINE)    Then $sX = $sX & "OFFLINE" & @LF
        If BitAND($ret[1], $INTERNET_CONNECTION_CONFIGURED) Then $sX = $sX & "CONFIGURED" & @LF
    Else
        $sX = "Not Connected"
    Endif

    MsgBox(4096,$ret[0] & ":" & $ret[1],$sX)

qq

Link to comment
Share on other sites

Fantastic, Burrup! Does that code already exist somewhere on the Scripts and Scraps forum?

Also, out of curiosity why do you use $sX & in the code below?

$sX = $sX & "MODEM" & @LF
Edited by LxP
Link to comment
Share on other sites

Fantastic, Burrup! Does that code already exist somewhere on the Scripts and Scraps forum?

Also, out of curiosity why do you use $sX & in the code below?

$sX = $sX & "MODEM" & @LF

<{POST_SNAPBACK}>

The ampersand symbol if for concatenating strings. So a command like this:

$sX = $sX & 'some literal string'

or

$sX = $sX & $sY

means that $sX now contains its original contents with the new string (literal or variable) concatenated on to the end.

Link to comment
Share on other sites

Thanks blindwig, but I was curious as to why this was being used when $sX was being explicitly cleared initially.

And then it dawned on me: possibly more than one if test may return true and so $sX may hold more than one flag at any time.

Apologies for the lack of attention earlier! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...