Skip to content

Commit c2ee562

Browse files
committed
Chore (__WD_CloseDriver): Rewrite to allow closure by PID
1 parent ffd6c75 commit c2ee562

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

wd_core.au3

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ EndFunc ;==>__WD_Error
17221722
; Name ..........: __WD_CloseDriver
17231723
; Description ...: Shutdown web driver console if it exists
17241724
; Syntax ........: __WD_CloseDriver([$sDriver = Default])
1725-
; Parameters ....: $sDriver - [optional] Web driver console to shutdown. Default is $_WD_DRIVER
1725+
; Parameters ....: $vDriver - [optional] The name or PID of Web driver console to shutdown. Default is $_WD_DRIVER
17261726
; Return values .: None
17271727
; Author ........: Dan Pollak
17281728
; Modified ......:
@@ -1731,30 +1731,35 @@ EndFunc ;==>__WD_Error
17311731
; Link ..........:
17321732
; Example .......: No
17331733
; ===============================================================================================================================
1734-
Func __WD_CloseDriver($sDriver = Default)
1735-
Local $sFile, $iID, $aData
1734+
Func __WD_CloseDriver($vDriver = Default)
1735+
Local $sFile, $aData, $aProcessList[2][2]
17361736

1737-
If $sDriver = Default Then $sDriver = $_WD_DRIVER
1737+
If $vDriver = Default Then $vDriver = $_WD_DRIVER
17381738

1739-
$sFile = StringRegExpReplace($sDriver, "^.*\\(.*)$", "$1")
1740-
1741-
Do
1742-
$iID = ProcessExists($sFile)
1739+
; Did calling routine pass a single PID?
1740+
If IsInt($vDriver) Then
1741+
; Yes, so build array to close this single instance
1742+
$aProcessList[0][0] = 1
1743+
$aProcessList[1][1] = $vDriver
1744+
Else
1745+
; No, close all matching driver instances
1746+
$sFile = StringRegExpReplace($vDriver, "^.*\\(.*)$", "$1")
1747+
$aProcessList = ProcessList($vDriver)
1748+
EndIf
17431749

1744-
If $iID Then
1745-
$aData = _WinAPI_EnumChildProcess($iID)
1750+
For $i = 1 To $aProcessList[0][0]
1751+
$aData = _WinAPI_EnumChildProcess($aProcessList[$i][1])
17461752

1747-
If IsArray($aData) Then
1748-
For $i = 0 To UBound($aData) - 1
1749-
If $aData[$i][1] = 'conhost.exe' Then
1750-
ProcessClose($aData[$i][0])
1751-
EndIf
1752-
Next
1753-
EndIf
1754-
1755-
ProcessClose($iID)
1753+
If IsArray($aData) Then
1754+
For $j = 0 To UBound($aData) - 1
1755+
If $aData[$j][1] == 'conhost.exe' Then
1756+
ProcessClose($aData[$j][0])
1757+
EndIf
1758+
Next
17561759
EndIf
1757-
Until Not $iID
1760+
1761+
ProcessClose($aProcessList[$i][1])
1762+
Next
17581763

17591764
EndFunc ;==>__WD_CloseDriver
17601765

0 commit comments

Comments
 (0)