Queener Posted January 7, 2014 Posted January 7, 2014 (edited) I want to loop kill the process if it exist anytime when windows is up and running. Here's what I have: $file = FileOpen("\\server-pc\mystuff$\Others\ListOfProcess\killallprocesses.txt", 0) Kill() Func Kill() While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $PID = ProcessExists($line) ConsoleWrite ( "$line : " & $line & @Crlf ) If $PID then ProcessClose($line) Wend Return EndFunc Now the problem is; once it reach the end of the text file line; it exitloop which the script stops. Edited January 7, 2014 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
BrewManNH Posted January 7, 2014 Posted January 7, 2014 Instead of using FileReadLine, use FileReadToArray and loop through the array instead, then you can just keep it in an endless loop. $file = FileOpen("\\server-pc\mystuff$\Others\ListOfProcess\killallprocesses.txt", 0) Kill() Func Kill() $aFile = FileReadToArray($file) While 1 For $Loop = 0 To UBound($aFile) $PID = ProcessExists($aFile[$Loop]) ConsoleWrite("$aFile[" & $Loop & "] : " & $aFile[$Loop] & @CRLF) If $PID Then ProcessClose($aFile[$Loop]) Next WEnd EndFunc ;==>Kill If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Queener Posted January 7, 2014 Author Posted January 7, 2014 (edited) I'm getting ERROR: FileReadToArray(): undefined function Edited January 7, 2014 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
BrewManNH Posted January 7, 2014 Posted January 7, 2014 It's in the latest version of AutoIt, as stated in my signature I only post code valid in what's currently available. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Queener Posted January 7, 2014 Author Posted January 7, 2014 (edited) I got win 7 and yet has the latest version of autoit. Windows is 64-bit; not sure if that affects. Edited January 7, 2014 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
BrewManNH Posted January 7, 2014 Posted January 7, 2014 I said the latest version of AutoIt, the version of Windows doesn't matter. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
aleph01 Posted January 7, 2014 Posted January 7, 2014 Sorry if I'm intruding, but what's wrong with simplicity? While 1 If ProcessExists (process.exe) Then ProcessClose (process.exe) EndIf Sleep (100) WEnd I use this with an annoying "End Process" window I sometimes experience. Meds. They're not just for breakfast anymore.
allSystemsGo Posted January 7, 2014 Posted January 7, 2014 asianqueen, You need to download the latest version of autoit. However, try using _FileReadToArray() and see if that works.
Gianni Posted January 8, 2014 Posted January 8, 2014 (edited) ok what allSystemsGo said, plus do not forget the #include <File.au3> at beginning of your script Edited January 8, 2014 by PincoPanco Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Moderators JLogan3o13 Posted January 8, 2014 Moderators Posted January 8, 2014 Sorry if I'm intruding, but what's wrong with simplicity? While 1 If ProcessExists (process.exe) Then ProcessClose (process.exe) EndIf Sleep (100) WEnd I use this with an annoying "End Process" window I sometimes experience. You did not read the OP. AsianQueen is looking to loop through an array of processes, and close them if active. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Queener Posted January 8, 2014 Author Posted January 8, 2014 (edited) Got the latest version of autoit. $aFile[0] : GoogleUpdateSetup.exe $aFile[1] : GoogleUpdate.exe $aFile[2] : GoogleToolBarSetup[1].exe "C:\Users\aq\Desktop\test.au3" (18) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $PID = ProcessExists($aFile[$Loop]) $PID = ProcessExists(^ ERROR Edited January 8, 2014 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
allSystemsGo Posted January 8, 2014 Posted January 8, 2014 Instead of using FileReadLine, use FileReadToArray and loop through the array instead, then you can just keep it in an endless loop. $file = FileOpen("\\server-pc\mystuff$\Others\ListOfProcess\killallprocesses.txt", 0) Kill() Func Kill() $aFile = FileReadToArray($file) While 1 For $Loop = 0 To UBound($aFile) $PID = ProcessExists($aFile[$Loop]) ConsoleWrite("$aFile[" & $Loop & "] : " & $aFile[$Loop] & @CRLF) If $PID Then ProcessClose($aFile[$Loop]) Next WEnd EndFunc ;==>Kill asianqueen, If you run the code above, what error do you get, if any?
Solution Queener Posted January 8, 2014 Author Solution Posted January 8, 2014 (edited) Got it!!! Kill() Func Kill() $aFile = FileReadToArray($file) While 1 Local $list = Processlist() For $i = 1 to $list[0][0] For $Loop = 0 To UBound($aFile) - 1 $PID = ProcessExists($aFile[$Loop]) ConsoleWrite("$aFile[" & $Loop & "] : " & $aFile[$Loop] & @CRLF) if StringRegExp($list[$i][0], $aFile[$Loop] & '.*$') then ProcessClose($List[$i][0]) ;If $PID Then ProcessClose($aFile[$Loop]) Next Next WEnd EndFunc ;==>Kill Thanks to everyone here. This is something I'm looking for. Very much appreciated. Edited January 8, 2014 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
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