break on
$Query = "SELECT TargetInstance.Name FROM __InstanceOperationEvent WITHIN 4 WHERE TargetInstance ISA 'Win32_NetworkAdapterConfiguration' and targetInstance.IPEnabled = true"
$objEvents = GetObject("winmgmts:\\.\root\cimv2").ExecNotificationQuery($query)
While 1
? 'waiting'
$objConnectEvent = $objEvents.nextevent
? 'event'
sleep 5
$aIPAddress = $objConnectEvent.TargetInstance.IPAddress
For Each $sAddress in $aIPAddress
? $sAddress
sleep 5
? 'pinging'
$Res = wmiPing('server',5000)
If not @error
? $res
$question=messagebox("Do you want to Start the Logon Script?","Network Detected",36)
if $question = 6
shell 'cmd /c start kix32 \\server\netlogon\kixtart.kix'
endif
endif
Next
loop
Function wmiPing($Address,Optional $Timeout,Optional $BlockSize)
Dim $Query,$oWMI,$oItem,$cItems
$Query = "Select ResponseTime,StatusCode From Win32_PingStatus Where Address='" + $Address + "'"
If $Timeout
$Query = $Query + " And TimeOut=" + $Timeout
EndIf
If $BlockSize
$Query = $Query + " And BufferSize=" + $BlockSize
EndIf
$oWMI = GetObject("winmgmts:root\cimv2")
$cItems = $oWMI.ExecQuery($Query)
For Each $oItem In $cItems
If (VarTypeName($oItem.StatusCode) = 'Null') Or $oItem.StatusCode
Exit 1
Else
$wmiPing = $oItem.ResponseTime
EndIf
Next
EndFunction