ETverde Posted March 5, 2022 Posted March 5, 2022 (edited) i did a script ho supost read a list in txt ad start a loop kiling proces on this list.... jus to keep away some proces with auto reload stuped sistens like microsofth ofice 1 clik to run and another bulshits of an pc werer i want some focus on do quic some simple jobs... the problem is... the script is running like all fine but the proces are no closing.... and i have no idea abouth why.... for some reason this part ( ProcessClose ($sFileRead) ) is just doing nothing.... expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <File.au3> $file = "list.txt" $iCountLines = 1 $g = 2 Do kill() Sleep(500) Until $g = 1 Func kill() $iCountLines = _FileCountLines("list.txt") Do Example() $iCountLines -= 1 Until $iCountLines = 1 EndFunc ;==>kill Func Example() ; Open the file for reading and store the handle to a variable. $hFileOpen = FileOpen($file, $FO_READ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") Return False EndIf ; Read the fist line of the file using the handle returned by FileOpen. $sFileRead = FileReadLine($hFileOpen, $iCountLines) ; Display procees ure kiling. ToolTip($iCountLines & " task kill:" & @CRLF & $sFileRead, 0, 0) ;~ shold kill the preces but just make me wate time ProcessClose($sFileRead) ; Close the handle returned by FileOpen. FileClose($hFileOpen) Sleep(500) EndFunc ;==>Example taskeer.au3 Edited March 5, 2022 by Jos Added script to post in codetags
Nine Posted March 5, 2022 Posted March 5, 2022 (edited) @ETverde Please use tags when you post code as described in the link, instead of attaching your script as a file. Could you show the content of the list.txt, since the process close is based on it. Also add an error handler after ProcessClose so we know the reason why it is failing... Edited March 5, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Developers Jos Posted March 5, 2022 Developers Posted March 5, 2022 You haven't provided any details of which process you are trying to kill. Also ensure that Script runs at the same level as the task you are trying to kill. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Trong Posted March 5, 2022 Posted March 5, 2022 (edited) You can use FileReadToArray to get a line-by-line array of the file: expandcollapse popupGlobal $FileListProcess = @ScriptDir & "\ListProcess4Kill.txt" Global $ArrayListProcess, $ProcessCount = 0 While 1 If Not FileExists($FileListProcess) Then Exit MsgBox(16 + 262144, "ERROR !", "File list process to kill is not Exists: " & @CRLF & $FileListProcess) $ArrayListProcess = _GetListProcess($FileListProcess) $ProcessCount = @extended If @error Then Exit MsgBox(16 + 262144, "ERROR !", "ERROR on Read File: " & @CRLF & $FileListProcess) For $i = 0 To $ProcessCount ; Loop through the array. ConsoleWrite("! Kill process: " & $ArrayListProcess[$i] & @CRLF) ; Display the contents of the array. If FileExists($ArrayListProcess[$i]) Then _ProcessCloseByPath($ArrayListProcess[$i]) Else _ProcessClose($ArrayListProcess[$i], 1) EndIf Next Sleep(1000) WEnd Func _GetListProcess($FileListProcess) ConsoleWrite("+ Reading the file: " & $FileListProcess & @CRLF) Local $_ArrayListProcess = FileReadToArray($FileListProcess) Local $_ProcessCount = @extended - 1 If @error Then ConsoleWrite("! There was an error reading the file. @error: " & @error & @CRLF) ; An error occurred reading the current script file. Return SetError(1, 0, 0) Else Return SetError(0, $_ProcessCount, $_ArrayListProcess) EndIf EndFunc ;==>_GetListProcess Func _ProcessClose($sProcess, $All = 0) Local $sPID = ProcessExists($sProcess) If Not $sPID Then Return SetError(0, 1, 0) Dim $Q = 0 If $All Then While ProcessExists($sProcess) ProcessClose($sProcess) Sleep(1) $Q += 1 If $Q > 10 Then ExitLoop WEnd If ProcessExists($sProcess) Then RunWait(@ComSpec & " /c taskkill /T /F /IM " & $sProcess, @SystemDir, @SW_HIDE) Else While ProcessExists($sPID) ProcessClose($sPID) Sleep(1) $Q += 1 If $Q > 10 Then ExitLoop WEnd If ProcessExists($sPID) Then RunWait(@ComSpec & " /c taskkill /T /F /PID " & $sPID, @SystemDir, @SW_HIDE) EndIf Return SetError(0, 0, ProcessExists($sPID) = 0) ; Dao Van Trong - TRONG.LIVE EndFunc ;==>_ProcessClose ; * -----:| Func _ProcessCloseByPath($sPath) ; ;#RequireAdmin 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) ; Dao Van Trong - TRONG.LIVE EndFunc ;==>_ProcessCloseByPath Edited March 5, 2022 by VIP FileReadToArray Regards,
ad777 Posted March 6, 2022 Posted March 6, 2022 @ETverde your script working fine just check list.txt:that should include .exe in last of process. ex:notepad.exe none
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now