Sign in to follow this  
Followers 0
Vinh

Kill Process

5 posts in this topic

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!

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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

When the words fail... music speaks

Share this post


Link to post
Share on other sites

#5 ·  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

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