Hallo Leute,
so mein Problem stellt sich so dar:
Ich habe eine reihe von Prozessen laufen (so 100 x ROBOCOPY.EXE im Beispiel is es die notepad.exe)
Also ich will diese ROBOCOPY's ab einem bestimmten Zeitpunkt alle Killen und dann mit anderen Parametern wieder aufrufen. (z.B. ab 19:00 full speed ab ab 22:00 1/2 speed wegen backup und dann wieder ab 03:00 full speed und dann wieder ab 05:00 Uhr 1/4 speed bis um 19:00Uhr)
Hier also meine Versuche.......
Spoiler anzeigen
Opt("MustDeclareVars", 1)
#include <Array.au3>
Local $exe = "notepad.exe"
_Process_Kill_btw_Times($exe, "09:11:00", "10:13:00")
Func _Process_Kill_btw_Times($exe, $StartTime, $EndTime)
Local $re = _processStartDateTime($exe)
Local $meld = 0
Local $list = _Processlist($exe)
While $list >= 0
;~ Local $list = _Processlist($exe)
If $meld = 1 Then
ExitLoop
EndIf
;~ Local $exe = "notepad.exe"
Local $date = @MDAY & "." & @MON & "." & @YEAR
;~ MsgBox(0, "", $date)
Local $time = @HOUR & ":" & @MIN & ":" & @SEC
;~ Local $re = _processStartDateTime($exe)
Local $meld = 0
If IsArray($re) Then
If $meld = 1 Then
ExitLoop
EndIf
For $i = 0 To $re[0][0]
Dim $arPIDS
Local $indexx = _ArrayBinarySearch($arPIDS, $re[$i][3])
_ArrayDisplay($arPIDS)
MsgBox(0, "", $indexx)
If $indexx = -1 Then $i = $i + 1
Select
Case $re[$i][2] > $EndTime
MsgBox(0, "PID" & $re[$i][3], $re[$i][3], 1)
ProcessClose($re[$i][3])
Sleep(5)
Case $re[$i][2] < $StartTime
MsgBox(0, "PID" & $re[$i][3], $re[$i][3], 1)
ProcessClose($re[$i][3])
Sleep(5)
Case $re[$i][2] >= $StartTime
MsgBox(0, $re[$i][3], $re[$i][2] & " in time", 1)
Local $tetst = _ArrayAdd($arPIDS, '"' & $re[$i][3] & '"')
MsgBox(0, "", $tetst)
_ArrayDisplay($arPIDS)
Sleep(1000)
Case $re[$i][2] <= $EndTime
MsgBox(0, $re[$i][3], $re[$i][2] & " in time", 1)
Local $tetst = _ArrayAdd($arPIDS, '"' & $re[$i][3] & '"')
MsgBox(0, "", $tetst)
_ArrayDisplay($arPIDS)
;~ $i = $i + 1
Sleep(1000)
;~ Case Else
EndSelect
Next
;~ $meld = 1
Else
MsgBox(64, "info", "Nichts mehr da", 1)
ExitLoop
EndIf
WEnd
Return $re
EndFunc ;==>_Process_Kill_btw_Times
Func _Processlist($exe)
Local $ProcessInfos = ''
;~ Local $Processname
Local $list = ProcessList($exe)
For $i = 1 To $list[0][0]
$ProcessInfos &= $list[$i][0] & " : " & $list[$i][1] & @CRLF
Next
Return $list[0][0]
;~ MsgBox(0,'Es gibt '&$list[0][0]&' Instanzen von '&$Process, $ProcessInfos)
EndFunc ;==>_Processlist
#cs
Return Code
0 = No Process found
-1 = Error - no object
Array with [Start Date][Start Time][processID]
#ce
Func _processStartDateTime($exe)
If Not ProcessExists($exe) Then Return 0
Local $process = '"' & $exe & '"'
Local $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process Where NAME = " & $process & "", "WQL", 0x10 + 0x20)
If Not IsObj($colItems) Then Return -1
Local $return[1][4], $counter = 0
For $objItem In $colItems
If $counter > 0 Then ReDim $return[$counter + 1][4]
Local $iDateCalc = StringMid($objItem.CreationDate, 7, 2) & "." & StringMid($objItem.CreationDate, 5, 2) & "." & StringLeft($objItem.CreationDate, 4)
Local $iTimeCalc = StringMid($objItem.CreationDate, 9, 2) & ":" & StringMid($objItem.CreationDate, 11, 2) & ":" & StringMid($objItem.CreationDate, 13, 2)
$return[$counter][0] = $counter
$return[$counter][1] = $iDateCalc
$return[$counter][2] = $iTimeCalc
$return[$counter][3] = $objItem.ProcessId
$counter += 1
Next
Return $return
EndFunc ;==>_processStartDateTime
Func _Prozkill($exe, $Killtime)
Local $meld = 0
Local $list = _Processlist($exe)
While $list >= 0
If $meld = 1 Then
ExitLoop
EndIf
;~ Local $exe = "notepad.exe"
Local $date = @MDAY & "." & @MON & "." & @YEAR
;~ MsgBox(0, "", $date)
Local $time = @HOUR & ":" & @MIN & ":" & @SEC
Local $re = _processStartDateTime($exe)
Local $list = _Processlist($exe)
Local $meld = 0
If IsArray($re) Then
If $meld = 1 Then
ExitLoop
EndIf
For $i = 0 To $re[0][0]
If $re[$i][1] <= $date And $re[$i][2] < $Killtime Then
;~ MsgBox(0, "PID" & $re[$i][3], $re[$i][3], 1)
ProcessClose($re[$i][3])
Sleep(5)
Else
MsgBox(0, "", "out of time", 1)
$meld = 1
EndIf
Next
Else
MsgBox(64, "info", "Nichts mehr da", 1)
ExitLoop
EndIf
WEnd
Return $re
EndFunc ;==>_Prozkill
Er bleibt mir immer bei der FOR Schleife hängen
danke für die Hilfe