Detect network and/or internet connectivity state Tag(s): WinAPI/Registry
[Local function declaration] FUNCTION boolean IsNetworkAlive(ref int flags) LIBRARY "sensapi.dll" [Powerscript] // The computer has one or more LAN cards that are active. CONSTANT integer NETWORK_ALIVE_LAN = 1; // The computer has one or more active RAS connections (internet). CONSTANT integer NETWORK_ALIVE_WAN = 2; // Win9x. The computer is connected to the America Online network. CONSTANT integer NETWORK_ALIVE_AOL = 4; OleObject wsh int networkState, k // to do the "bitwise AND" later... wsh = CREATE OleObject wsh.ConnectToNewObject( "MSScriptControl.ScriptControl" ) wsh.language = "vbscript" IF IsNetworkAlive(networkState) THEN // check if a network card is active k = integer(wsh.Eval( string(networkState) + & " AND " + & string(NETWORK_ALIVE_LAN))) IF k = NETWORK_ALIVE_LAN THEN MessageBox("","network is ON") ELSE MessageBox("","network is OFF") END IF // check if internet connection is active k = integer(wsh.Eval( string(networkState) + & " AND " + & string(NETWORK_ALIVE_WAN))) IF k = NETWORK_ALIVE_WAN THEN MessageBox("","internet is ON") ELSE MessageBox("","internet is OFF") END IF ELSE MessageBox("","no network ?!?") END IF
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com