Jump to content

Detecting active connection


Recommended Posts

Hi everybody. I'm new to AutoIt, and I humbly request your kind help ;) I need to make a script which detects if there's an active connection to a LAN or WLAN, and then - if the connection exists - runs a batch or .exe file. I know how to do for the second part, but I don't know how to detect the active connection. Thank you in advance for your help.

Link to comment
Share on other sites

minoilrosso

Welcome!

Try this:

Global Const $NETWORK_ALIVE_LAN = 0x1  ;net card connection
Global Const $NETWORK_ALIVE_WAN = 0x2  ;RAS connection
Global Const $NETWORK_ALIVE_AOL = 0x4  ;AOL

$connect = _GetNetworkConnect()

If $connect Then
    MsgBox(64, "Connections", $connect)
Else
    MsgBox(48, "Warning", "There is no connection")
EndIf

Func _GetNetworkConnect($sType = $NETWORK_ALIVE_LAN)
    Local $tTYPE, $iData, $iResult
    
    $tTYPE = DllStructCreate("int")
    
    DllCall("sensapi.dll", "int", "IsNetworkAlive", "ptr", DllStructGetPtr($tTYPE))
    
    $iData = DllStructGetData($tTYPE, 1)
    
    If BitAND($iData, $NETWORK_ALIVE_LAN) Then $iResult &= "LAN connected" & @LF
    If BitAND($iData, $NETWORK_ALIVE_WAN) Then $iResult &= "WAN connected" & @LF
    If BitAND($iData, $NETWORK_ALIVE_AOL) Then $iResult &= "AOL connected" & @LF
    
    Return $iResult
EndFunc

;)

Link to comment
Share on other sites

Try this:

Global Const $NETWORK_ALIVE_LAN = 0x1  ;net card connection
Global Const $NETWORK_ALIVE_WAN = 0x2  ;RAS connection
Global Const $NETWORK_ALIVE_AOL = 0x4  ;AOL

$connect = _GetNetworkConnect()

If $connect Then
    MsgBox(64, "Connections", $connect)
Else
    MsgBox(48, "Warning", "There is no connection")
EndIf

Func _GetNetworkConnect($sType = $NETWORK_ALIVE_LAN)
    Local $tTYPE, $iData, $iResult
    
    $tTYPE = DllStructCreate("int")
    
    DllCall("sensapi.dll", "int", "IsNetworkAlive", "ptr", DllStructGetPtr($tTYPE))
    
    $iData = DllStructGetData($tTYPE, 1)
    
    If BitAND($iData, $NETWORK_ALIVE_LAN) Then $iResult &= "LAN connected" & @LF
    If BitAND($iData, $NETWORK_ALIVE_WAN) Then $iResult &= "WAN connected" & @LF
    If BitAND($iData, $NETWORK_ALIVE_AOL) Then $iResult &= "AOL connected" & @LF
    
    Return $iResult
EndFuncoÝ÷ Ûú®¢×jȦÊjzÞÞ¶T­®ç-~éܶ*'°9e ©eÂ)ejYhq«^i»}êçjدzºÚ"µÍÛØ[ÛÛÝ    ÌÍÓUÓÔ×ÐSUWÓSHHÛ]ØÛÛXÝ[ÛÛØ[ÛÛÝ   ÌÍÓUÓÔ×ÐSUWÕÐSHÔTÈÛÛXÝ[ÛÛØ[ÛÛÝ  ÌÍÓUÓÔ×ÐSUWÐSÓH
ÐSÓÌÍØÛÛXÝHÑÙ]]ÛÜÐÛÛXÝ

BY^[Y[ÙÐÞ
    ][ÝÐÛÛXÝ[ÛÉ][ÝË    ÌÍØÛÛXÝ
B[ÙBÙÐÞ
    ][ÝÕØ[É][ÝË   ][ÝÕHÈÈÛÛXÝ[Û][ÝÊB[Y[ÈÑÙ]]ÛÜÐÛÛXÝ

BNÈ^[YÙ]H[Ý[ÛÛ]ÙHÈÛÛX[ ÌÎNÒÐÛÛXÝY   ÌÎNÂSØØ[   ÌÍØTÝ[  ÌÍÜÔÝ[H    ][ÝÉ][ÝË    ÌÍÚQ]K   ÌÍÚQÜH  ÌÍØTÝ[HØ[
    ][ÝÜÙ[ØK    ][ÝË  ][ÝÚ[ ][ÝË  ][ÝÒÓ]ÛÜÐ[]I][ÝË    ][ÝÚ[
][ÝË
BIÌÍÚQÜHÜRYÜÜÐ^J    ÌÍØTÝ[
HH[]Ù]Ü   ÌÍÚQÜ   ][ÝÉ][ÝÊBIÌÍÚQ]HH    ÌÍØTÝ[ÌWBY]S
    ÌÍÚQ]K   ÌÍÓUÓÔ×ÐSUWÓSH[ ÌÍÜÔÝ[ [ÏH    ][ÝÓSÛÛXÝY ][ÝÈ  [ÈY]S
    ÌÍÚQ]K   ÌÍÓUÓÔ×ÐSUWÕÐSH[   ÌÍÜÔÝ[ [ÏH    ][ÝÕÐSÛÛXÝY   ][ÝÈ  [ÈY]S
    ÌÍÚQ]K   ÌÍÓUÓÔ×ÐSUWÐSÓ
H[  ÌÍÜÔÝ[ [ÏH    ][ÝÐSÓÛÛXÝY   ][ÝÈ  [È]Ù]Ü   ÌÍÚQÜ   ÌÍØTÝ[ÌK   ÌÍÜÔÝ[
B[[

I see fascists...

Link to comment
Share on other sites

rover

Right, but i think both our solutions is correct ;)

Rasim, yes they are :D

I was just pointing out that some lines of code can be saved for simple

struct requirements with DllCall.

just for future reference and for anyone else who comes along.

Cheers

I see fascists...

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...