Jump to content

Bad Snippets ! _ProcessCloseFromPath()


Trong
 Share

Recommended Posts

https://www.autoitscript.com/wiki/Snippets_(_Windows_OS_)

Test

Example()

Func Example()
    ; Close a process using the filepath rather than the filename, which is what ProcessClose requires.

    Run("C:\Windows\System32\notepad.exe") ;
    Run("C:\Windows\SysWOW64\notepad.exe") ;

    ; Wait 10 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 10)

    ; Wait for 2 seconds.
    Sleep(2000)

    Local $sNotepad = "C:\Windows\SysWOW64\notepad.exe"
    MsgBox(48, "", "Path of Notepad: " & $sNotepad)

    ; Close the Notepad process using the filepath.
    _ProcessCloseFromPath($sNotepad)
EndFunc   ;==>Example

Func _ProcessCloseFromPath($sFilePath)
    Return FileExists($sFilePath) ? ProcessClose(StringTrimLeft($sFilePath, StringInStr($sFilePath, "\", Default, -1))) : SetError(1, 0, 0)
EndFunc   ;==>_ProcessCloseFromPath 

I maybe permitted to modify a function better?
 

StringTrimLeft($sFilePath, StringInStr($sFilePath, "\", Default, -1))

Regards,
 

Link to comment
Share on other sites

 

https://www.autoitscript.com/wiki/Snippets_(_Windows_OS_)

Test

Example()

Func Example()
    ; Close a process using the filepath rather than the filename, which is what ProcessClose requires.

    Run("C:\Windows\System32\notepad.exe") ;
    Run("C:\Windows\SysWOW64\notepad.exe") ;

    ; Wait 10 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 10)

    ; Wait for 2 seconds.
    Sleep(2000)

    Local $sNotepad = "C:\Windows\SysWOW64\notepad.exe"
    MsgBox(48, "", "Path of Notepad: " & $sNotepad)

    ; Close the Notepad process using the filepath.
    _ProcessCloseFromPath($sNotepad)
EndFunc   ;==>Example

Func _ProcessCloseFromPath($sFilePath)
    Return FileExists($sFilePath) ? ProcessClose(StringTrimLeft($sFilePath, StringInStr($sFilePath, "\", Default, -1))) : SetError(1, 0, 0)
EndFunc   ;==>_ProcessCloseFromPath 

I maybe permitted to modify a function better?

 

StringTrimLeft($sFilePath, StringInStr($sFilePath, "\", Default, -1))

 

I know this is not your function, but you use it like the function could really know where the path of the running process is. But it does not. This works too:

Example()

Func Example()
    ; Close a process using the filepath rather than the filename, which is what ProcessClose requires.

    Run("C:\Windows\System32\notepad.exe") ;
;~     Run("C:\Windows\SysWOW64\notepad.exe") ;

    ; Wait up to 10 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 10)

    ; Wait for 2 seconds.
    Sleep(2000)

    Local $sNotepad = "C:\Windows\SysWOW64\notepad.exe"
    MsgBox(48, "", "Path of Notepad: " & $sNotepad)

    ; Close the Notepad process using the filepath.
    _ProcessCloseFromPath($sNotepad)
EndFunc   ;==>Example

Func _ProcessCloseFromPath($sFilePath)
    Return FileExists($sFilePath) ? ProcessClose(StringTrimLeft($sFilePath, StringInStr($sFilePath, "\", Default, -1))) : SetError(1, 0, 0)
EndFunc   ;==>_ProcessCloseFromPath

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

concur, if you are just using the filename to execute...why look for the fileexists as opposed to just looking for the process?

#include <Array.au3>

Example()

Func Example()
    Local $sNotepad = "C:\Windows\System32\notepad.exe"
    Run($sNotepad)
    Sleep(2000)
    _ProcessCloseFromPath($sNotepad)
EndFunc   ;==>Example

Func _ProcessCloseFromPath($sFilePath)
    $aProc = StringSplit($sFilePath , "\" , 0)
    Return ProcessExists($aProc[$aProc[0]]) ?  ProcessClose($aProc[$aProc[0]]) : SetError(1, 0, 0)
EndFunc   ;==>_ProcessCloseFromPath
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Above is the original content, do not fix anything!
It comes with examples and functions make it work incorrectly.

I'm writing and experiment new function.
It works better and more accurate.
It is nearing completion.

Regards,
 

Link to comment
Share on other sites

@boththose - Probably because of this

; Close a process using the filepath rather than the filename, which is what ProcessClose requires.

Although the "why" of it escapes me.   Oh, I see, muiltiple instances from different locations...

@Trong - Can you explain how to get "better" and "more accurate" than what funkey and boththose posted?  Just curious...

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

a WMI version.

Run("C:\Windows\SysWOW64\notepad.exe")
Run("C:\Users\notepad.exe")

sleep(2500)

_ProcessCloseByPath("C:\Windows\SysWOW64\notepad.exe")


Func _ProcessCloseByPath($sPath)


$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\ROOT\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
        $sExePath = $objItem.ExecutablePath
        If $sExePath = $sPath Then
            $sPID = $objItem.ProcessId
            processclose($sPID)
        EndIf
    Next
Endif

EndFunc
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

better, as the WMI query only returns the necessary info

Run("C:\Windows\SysWOW64\notepad.exe")
Run("C:\Users\notepad.exe")

sleep(2500)

_ProcessCloseByPath("C:\Windows\SysWOW64\notepad.exe")


Func _ProcessCloseByPath($sPath)


$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\ROOT\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT ExecutablePath,ProcessId FROM Win32_Process WHERE ExecutablePath = " & '"' & stringreplace($sPath, "\" , "\\") & '"', "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
            $sPID = $objItem.ProcessId
            processclose($sPID)
    Next
Endif

EndFunc 
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

; #FUNCTION# ===============================================================================
; Name...........: __ProcessCloseByPath()
; Author ........: boththose
; Modified.......: Trong - reformated
Func _ProcessCloseByPath($sPath);
    Local $colItems = "",$strComputer = "localhost",$wbemFlagReturnImmediately = 0x10,$wbemFlagForwardOnly = 0x20;
    Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\ROOT\CIMV2"),$sFailure = 0,$sSuccess=1;
    Local $cQuery="SELECT ExecutablePath,ProcessId FROM Win32_Process WHERE ExecutablePath = " & '"' & StringReplace($sPath, "\" , "\\") & '"'
    $colItems = $objWMIService.ExecQuery($cQuery, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly);
    If IsObj($colItems) then;
       For $objItem In $colItems;
            Local $sPID = $objItem.ProcessId;
            ProcessClose($sPID);
            If ProcessExists($sPID) Then $sFailure += 1;
        Next;
    Endif;
    If $sFailure Then $sSuccess = 0;
    Return SetError($sFailure, 0, $sSuccess);
EndFunc   ;==>__ProcessCloseByPath

Regards,
 

Link to comment
Share on other sites

Trong,

Run this

$iPid1 = Run("C:\Windows\System32\notepad.exe") ;
$iPid2 = Run("C:\Windows\SysWOW64\notepad.exe") ;

ConsoleWrite('"C:\Windows\System32\notepad.exe" PID =  ' & $iPid1 & @CRLF)
ConsoleWrite('"C:\Windows\SysWOW64\notepad.exe" PID =  ' & $iPid2 & @CRLF)

; Wait 10 seconds for the Notepad window to appear.
WinWait("[CLASS:Notepad]", "", 10)

; Wait for 2 seconds.
Sleep(2000)

Local $sNotepad = "C:\Windows\SysWOW64\notepad.exe"
MsgBox(48, "", "Path of Notepad: " & $sNotepad)

; Close the Notepad process using the filepath.
_ProcessCloseByPath($sNotepad)

; #FUNCTION# ===============================================================================
; Name...........: __ProcessCloseByPath()
; Author ........: boththose
; Modified.......: Trong - reformated
Func _ProcessCloseByPath($sPath);
    Local $colItems = "",$strComputer = "localhost",$wbemFlagReturnImmediately = 0x10,$wbemFlagForwardOnly = 0x20;
    Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\ROOT\CIMV2"),$sFailure = 0,$sSuccess=1;
    Local $cQuery="SELECT ExecutablePath,ProcessId FROM Win32_Process WHERE ExecutablePath = " & '"' & StringReplace($sPath, "\" , "\\") & '"'
    $colItems = $objWMIService.ExecQuery($cQuery, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly);
    If IsObj($colItems) then;
       For $objItem In $colItems;
            Local $sPID = $objItem.ProcessId;
            ConsoleWrite('closing pid = ' & $sPID & @CRLF)
            ProcessClose($sPID);
            If ProcessExists($sPID) Then $sFailure += 1;
        Next;
    Endif;
    If $sFailure Then $sSuccess = 0;
    Return SetError($sFailure, 0, $sSuccess);
EndFunc   ;==>__ProcessCloseByPath

both instances of NotePad are being closed. 

Also, de facto convention is to use "i" to designate an integer variable, as in $iPid. 

kylomas

edit: This technique may not work.  M$ is returning both PID's under the same executable path, possibly because of re-direction...

Run this

$iPid1 = Run("C:\Windows\System32\notepad.exe") ;
$iPid2 = Run("C:\Windows\SysWOW64\notepad.exe") ;

ConsoleWrite('"C:\Windows\System32\notepad.exe" PID =  ' & $iPid1 & @CRLF)
ConsoleWrite('"C:\Windows\SysWOW64\notepad.exe" PID =  ' & $iPid2 & @CRLF)

; Wait 10 seconds for the Notepad window to appear.
WinWait("[CLASS:Notepad]", "", 10)

; Wait for 2 seconds.
Sleep(2000)

Local $sNotepad = "C:\Windows\SysWOW64\notepad.exe"
MsgBox(48, "", "Path of Notepad: " & $sNotepad)

; Close the Notepad process using the filepath.
_ProcessCloseByPath($sNotepad)

; #FUNCTION# ===============================================================================
; Name...........: __ProcessCloseByPath()
; Author ........: boththose
; Modified.......: Trong - reformated
Func _ProcessCloseByPath($sPath);
    Local $colItems = "",$strComputer = "localhost",$wbemFlagReturnImmediately = 0x10,$wbemFlagForwardOnly = 0x20;
    Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\ROOT\CIMV2"),$sFailure = 0,$sSuccess=1;
    Local $cQuery="SELECT ExecutablePath,ProcessId FROM Win32_Process WHERE ExecutablePath = " & '"' & StringReplace($sPath, "\" , "\\") & '"'
    $colItems = $objWMIService.ExecQuery($cQuery, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly);
    If IsObj($colItems) then;
       For $objItem In $colItems;
            Local $sPID = $objItem.ProcessId;
            ConsoleWrite('closing pid = ' & $sPID & ' path = ' & $objitem.executablepath & @CRLF)
            ProcessClose($sPID);
            If ProcessExists($sPID) Then $sFailure += 1;
        Next;
    Endif;
    If $sFailure Then $sSuccess = 0;
    Return SetError($sFailure, 0, $sSuccess);
EndFunc   ;==>__ProcessCloseByPath
Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Trong,

You may be able to use "commandline" to differentiate the runs of notepad.  Run the following to see what Win32_Process gives you.  If you use "commandline"  you will have to strip off run time parms.

#RequireAdmin
#include <array.au3>

Local $ret
$ret = _WMI('select * from Win32_Process where name = "notepad.exe"')

If @error Then Exit (ConsoleWrite(@LF & '!> @ERROR    = ' & @error & @LF & '!> @EXTENDED = ' & @extended & @LF & '!> $RET      = ' & $ret & @LF & @LF))
If IsArray($ret) Then _ArrayDisplay($ret)
If IsString($ret) Then ConsoleWrite($ret & @CRLF)

; #FUNCTION# ====================================================================================================================
; Name...........: _WMI
; Description ...: Returns formatted output from a query against any class of the CIMV2 namespace using WMI.
; Syntax.........: _WMI($sWQL, $bReturnType, $sDelimiter, $sTargetPC)
; Parameters ....: $sWQL            - Any class in the WMI CIMV2 namespace (e.g. Win32_Process, Win32_BIOS, Win32_Desktop, etc.)
;                                     or any WQL 'Select' query.  If only the class is specified then all columns
;                                     for all items are returned.
;                  $bReturnType     - Indicates return format.  $bReturnType can be a string or integer.
;                                   |0 - Return a 2D array with item names in col 0 (on the left).
;                                   |1 - Return a 2D array with item names in row 0 (on top).      (DEFAULT)
;                                   |2 - Return a @CRLF delimited string of item names (row #1) followed by items.  Each value is
;                                        delimited by $sDelimiter.
;                  $sDelimiter      - The delimiter used to seperate values/property names within an item.  The default is
;                                     '`' because other common delimiter characters (e.g. '|', ',', '=', ':', '~' etc. appear
;                                     in some values returned by various WQL queries.  This can be a string of characters (e.g. '//').
;                  $sTargetPC       - Name of the PC to run the query on.
; Return values .: Success          - A 2D array or string depending on $bReturnType.
;                  Failure          - Sets @ERROR and returns a value as follows:
;                                   |1 - $sWQL is blank                     Return value - None
;                                   |2 - $bReturnType invalid               Return value - The parm supplied
;                                   |3 - $sDelimiter not specified          Return value - None
;                                   |4 - WMI ObjGet failure                 Return value - None
;                                   |5 - ExecQuery failure                  Return value - $sWQL
;                                   |6 - No items returned                  Return value - $sWQL
;
; Author ........: kylomas
; Modified.......: 02/02/2015 V01R01M01 initial release
; Remarks .......:
; Related .......: WMI is required
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================

Func _WMI($sWQL, $bReturnType = 1, $sDelimiter = '`', $sTargetPC = @ComputerName)

    ; flush parms
    Switch $bReturnType
        Case 0, 1, 2, '0', '1', '2'
        Case -1, Default
            $bReturnType = 1
        Case Else
            Return SetError(2, 0, $bReturnType)
    EndSwitch

    Switch True
        Case $sDelimiter = -1 Or $sDelimiter = Default
            $sDelimiter = '`'
        Case StringLen($sDelimiter) > 0
        Case Else
            Return SetError(3, 0, $sDelimiter)
    EndSwitch

    If StringLen($sWQL) = 0 Then Return SetError(1)
    If StringInStr($sWQL, 'select') = 0 Then $sWQL = 'select * from ' & $sWQL

    Local $oWMI = '', $oItem = '', $oItems = '', $P = ''

    ; Get WMI instance
    ; Do NOT use $wbemFlagReturnImmediately or $wbeForwardOnly as this disables the "Count" property
    $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sTargetPC & "\root\CIMV2")
    If Not IsObj($oWMI) Then Return SetError(4)

    ; Run query
    $oItems = $oWMI.ExecQuery($sWQL)
    If Not IsObj($oItems) Then Return SetError(5, 0, $sWQL)
    If $oItems.count = 0 Then Return SetError(6, 0, $sWQL)

    Local $str = ''

    ; format header / use this method as opposed to the "itemindex" method for XP compatibility
    For $oItem In $oItems
        For $P In $oItem.Properties_()
            $str &= '<' & $P.Name & '>' & $sDelimiter
        Next
        $str = StringTrimRight($str, StringLen($sDelimiter)) & @CRLF
        ExitLoop
    Next

    ; format each detail item
    For $oItem In $oItems
        For $P In $oItem.Properties_()
            Switch True
                Case $P.isarray
                    $aTmp1 = $P.Value
                    $str &= _ArrayToString($aTmp1, '') & $sDelimiter
                Case $P.CIMTYPE = 101
                    $str &= CNVTDate($P.Value) & $sDelimiter
                Case Else
                    $str &= $P.Value & $sDelimiter
            EndSwitch
        Next
        $str = StringTrimRight($str, StringLen($sDelimiter)) & @CRLF
    Next
    $str = StringTrimRight($str, 2)

    Switch $bReturnType
        Case '1', 1, -1, Default
            ; return 2D array / column names are at top (row 0)
            Local $aTmp1 = StringSplit($str, @CRLF, 3), $aTmp2
            Local $aRet[UBound($aTmp1)][UBound(StringSplit($aTmp1[0], $sDelimiter, 3))]
            For $1 = 0 To UBound($aTmp1) - 1
                $aTmp2 = StringSplit($aTmp1[$1], $sDelimiter, 3)
                For $2 = 0 To UBound($aTmp2) - 1
                    $aRet[$1][$2] = $aTmp2[$2]
                Next
            Next
            Return $aRet
        Case '0', 0
            ; return 2D array / column names are to the left (col 0)
            Local $aTmp1 = StringSplit($str, @CRLF, 3), $aTmp2
            Local $aRet[UBound(StringSplit($aTmp1[0], $sDelimiter, 3))][UBound($aTmp1)]
            For $1 = 0 To UBound($aTmp1) - 1
                $aTmp2 = StringSplit($aTmp1[$1], $sDelimiter, 3)
                For $2 = 0 To UBound($aTmp2) - 1
                    $aRet[$2][$1] = $aTmp2[$2]
                Next
            Next
            Return $aRet
        Case '2', 2
            ; return string
            Return $str
        Case Else
            Return SetError(7, 0, $bReturnType)
    EndSwitch

EndFunc   ;==>_WMI

Func CNVTDate($dtmDate)
    ; reformat date to mm/dd/yyyy hh:mm:ss and zero fill single digit values
    Return StringRegExpReplace(StringRegExpReplace($dtmDate, '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}).*', '$2/$3/$1 $4:$5:$6'), '(?<!\d)(\d/)', '0$1')
EndFunc   ;==>CNVTDate
Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

@kylomas @boththose

Thanks for WMI

This function is what I'm looking for.

I have many projects, but it has not been completed because document limited.

I'm learning more about WinAPI.

Regards,
 

Link to comment
Share on other sites

or add the one line to turn redirection off...I dont think that burden falls on the function though,  if the user is going to play with syswow and sys32 stuff then the user should turn redirection off, as many other functions will behave unexpectedly in similar fashion.

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)

Run("C:\Windows\System32\notepad.exe")
Run("C:\Windows\SysWOW64\notepad.exe")

sleep(2500)

_ProcessCloseByPath("C:\Windows\SysWOW64\notepad.exe")


Func _ProcessCloseByPath($sPath)


$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\ROOT\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT ExecutablePath,ProcessId FROM Win32_Process WHERE ExecutablePath = " & '"' & stringreplace($sPath, "\" , "\\") & '"', "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
            $sPID = $objItem.ProcessId
            processclose($sPID)
    Next
Endif

EndFunc
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

CommandLine is bad for get path of Executable !

Trong,

You may be able to use "commandline" to differentiate the runs of notepad.  Run the following to see what Win32_Process gives you.  If you use "commandline"  you will have to strip off run time parms.

 

or add the one line to turn redirection off...I dont think that burden falls on the function though,  if the user is going to play with syswow and sys32 stuff then the user should turn redirection off, as many other functions will behave unexpectedly in similar fashion.

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)

Not need turn redirection off! It work !

 

; #FUNCTION# ===============================================================================
; Name...........: __ProcessCloseByPath()
; Author ........: boththose
; Modified.......: Trong - reformated
Func _ProcessCloseByPath($sPath);
    Local $colItems = "",$strComputer = "localhost",$wbemFlagReturnImmediately = 0x10,$wbemFlagForwardOnly = 0x20;
    Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\ROOT\CIMV2"),$sFailure = 0,$sSuccess=1;
    Local $cQuery="SELECT ExecutablePath,ProcessId FROM Win32_Process WHERE ExecutablePath = " & '"' & StringReplace($sPath, "\" , "\\") & '"'
    $colItems = $objWMIService.ExecQuery($cQuery, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly);
    If IsObj($colItems) then;
       For $objItem In $colItems;
            Local $sPID = $objItem.ProcessId;
            ConsoleWrite('closing pid = ' & $sPID & ' path = ' & $objitem.executablepath & @CRLF)
            ProcessClose($sPID);
            If ProcessExists($sPID) Then $sFailure += 1;
        Next;
    Endif;
    If $sFailure Then $sSuccess = 0;
    Return SetError($sFailure, 0, $sSuccess);
EndFunc   ;==>__ProcessCloseByPath
KJ

Regards,
 

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