Sign in to follow this  
Followers 0
Delta01

_CheckProcessConnect()

3 posts in this topic

#1 ·  Posted (edited)

Can someone tell me why the below code doesn't work, please.

#include <Constants.au3>

MsgBox(64, "Returned", _CheckProcessConnect("firefox.exe") & @CR & @ERROR)


;===============================================================================
;
; Description:      Checks if a process is connected - to the internet / to a specific IP
; Syntax:           _CheckProcessConnect($sProcess,$iIp = False)
; Parameter(s):     $sProcess = Processname / Process ID to look for
;                    $iIp = The IP that the Process should be connected to [ optional! ]
; Requirement(s):   None
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0 and sets @error
;                    1 = No connection exists
;                    2 = Process does not exist
;                    3 = No german Windows
; Author(s):        qon
; Note(s):          None
;
;===============================================================================

Func _CheckProcessConnect($sProcess,$iIp = False)
    $iPID = ProcessExists($sProcess)
    If $iPID = 0 then
        SetError(2)
        Return 0
    EndIf
    $foo = Run(@ComSpec & " /c netstat -on", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While 1
        $line = StdoutRead($foo)
        If @error Then ExitLoop
        Switch $iIp
            Case False
                If StringInStr(" " & $line & " ",$iPID) and StringInStr(" " & $line & " ","HERGESTELLT") Then
                    Return 1
                EndIf
            Case Else
                If StringInStr(" " & $line & " ",$iPID) and StringInStr(" " & $line & " ","HERGESTELLT") and StringInStr(" " & $line & " ",$iIp) Then
                    Return 1
                EndIf
        EndSwitch
    Wend
    SetError(1)
    Return 0
EndFunc

If there is a connection to the internet, it should return 1

Edited by Delta01

Share this post


Link to post
Share on other sites



Thanks, works now

Share this post


Link to post
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
Sign in to follow this  
Followers 0