Jump to content

Recommended Posts

Posted

Sr, my english's very bad :)

I have 2 process:

+ Test.exe path in C:\Test.exe

+ Test.exe path in D:\Test.exe

Their name is both Test.exe

I want to close process "Test.exe" (path in C:\Test.exe) but if I use ProcessClose("Test.exe"), It will close process "Test.exe" (path in D:\Test.exe) and i don't want it close that process :P .

Please help me to close that process I want to close. :)

Thanks all!

Posted

Sr, my english's very bad :)

I have 2 process:

+ Test.exe path in C:\Test.exe

+ Test.exe path in D:\Test.exe

Their name is both Test.exe

I want to close process "Test.exe" (path in C:\Test.exe) but if I use ProcessClose("Test.exe"), It will close process "Test.exe" (path in D:\Test.exe) and i don't want it close that process :P .

Please help me to close that process I want to close. :)

Thanks all!

You could always just change one of the file names.

Posted

Try this:

$PROC_LIST = ProcessList("test.exe")
If IsArray($PROC_LIST) Then
    For $INDEX = 1 To $PROC_LIST[0][0]
        If ProcessGetPath($PROC_LIST[$INDEX][1]) = "C:\Test.exe" Then ProcessClose($PROC_LIST[$INDEX][1])
    Next
EndIf

Func ProcessGetPath($PID)
    Local $PATH = ""
    $OBJ = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy, (Debug)}!\\.\root\cimv2")
    If IsObj($OBJ) Then
        $PROC = $OBJ.ExecQuery("select * from win32_Process where ProcessId = " & $PID)
        If IsObj($PROC) Then
            If $PROC.count <> 0 Then
                For $FIND In $PROC
                    $PATH = $FIND.ExecutablePath
                    If $PATH <> "" Then ExitLoop
                Next
            EndIf
        EndIf
    EndIf
    Return $PATH
EndFunc
Posted (edited)

Try this:

$PROC_LIST = ProcessList("test.exe")
If IsArray($PROC_LIST) Then
    For $INDEX = 1 To $PROC_LIST[0][0]
        If ProcessGetPath($PROC_LIST[$INDEX][1]) = "C:\Test.exe" Then ProcessClose($PROC_LIST[$INDEX][1])
    Next
EndIf

Func ProcessGetPath($PID)
    Local $PATH = ""
    $OBJ = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy, (Debug)}!\\.\root\cimv2")
    If IsObj($OBJ) Then
        $PROC = $OBJ.ExecQuery("select * from win32_Process where ProcessId = " & $PID)
        If IsObj($PROC) Then
            If $PROC.count <> 0 Then
                For $FIND In $PROC
                    $PATH = $FIND.ExecutablePath
                    If $PATH <> "" Then ExitLoop
                Next
            EndIf
        EndIf
    EndIf
    Return $PATH
EndFunc

Oh, sr, it working :)

Thank you very much :)

Edited by Vinh

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
  • Recently Browsing   0 members

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