ghostofdeath Posted May 19, 2007 Share Posted May 19, 2007 (edited) Basically, I want to check if a process exists from a process list that i have, and If one of them exists, close that, then return the loop my (noobish) code is that: Dim $process[31] $process[1]="wordpad.exe" $process[2]="notepad.exe" for $x=0 to 2 msgbox(0, $x, $process[$x]&@LF) Next If ProcessExists($process) Then ProcessClose($process) EndIf PS:the msgbox is just to check the variables results Thx~~ Edit:There's a way to put all the processes names "together", i mean dun put every process in a array value but in one line or variable separated by comma or anything else? Edited May 19, 2007 by ghostofdeath Link to comment Share on other sites More sharing options...
Davo Posted May 19, 2007 Share Posted May 19, 2007 (edited) First of all this code: If ProcessExists($process) Then ProcessClose($process) EndIf There is also another method where you can store all the processes in an easy to edit text file, so just a basic .txt and then read each line of the txt and compare the line with the process that exists and close it if thats the case. Anway there is many ways it can be done there is also a processList function that lists all the current processes in an array and then you can sort that array for what exists and kill the processes you dont want running. If you are a bit more specific about your scenario I will probably be able to help you more. Hope this helps. Dave Edited May 19, 2007 by Davo ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!! Link to comment Share on other sites More sharing options...
ghostofdeath Posted May 19, 2007 Author Share Posted May 19, 2007 There is also another method where you can store all the processes in an easy to edit text file, so just a basic .txt and then read each line of the txt and compare the line with the process that exists and close it if thats the case. Anway there is many ways it can be done there is also a processList function that lists all the current processes in an array and then you can sort that array for what exists and kill the processes you dont want running. If you are a bit more specific about your scenario I will probably be able to help you more.Hope this helps. DaveThx Dave.. the ubound command i didnt know, anyway i want to close all processes found on array , and there's a way to do the '.txt' file in like a '.anything' file? i write the file in notepad and then 'save as..' .anything, then fileread() ? Link to comment Share on other sites More sharing options...
SadBunny Posted May 19, 2007 Share Posted May 19, 2007 Thx Dave.. the ubound command i didnt know, anyway i want to close all processes found on array , and there's a way to do the '.txt' file in like a '.anything' file? i write the file in notepad and then 'save as..' .anything, then fileread() ? You can use _FireReadToArray if you want to read ANY file to an array. In this way you can write a plaintext file (file extension is up to you), then do something like the following: Dim $a[1] _FileReadToArray("c:\myfile",$a) For $loop = 0 to $a[0] ; <-- The 0'th position of the array will tell how many lines are read ; <-- do whatever you want to the process Next Also... EXTENSIVE Process info (and a LOT of other computer information) can be retrieved easily by using the functions in CompInfo.au3: http://www.autoitscript.com/forum/index.ph...st&id=12096 Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Shevilie Posted May 19, 2007 Share Posted May 19, 2007 A easier way to loop an array is like this For $proces In $process If ProcessExists($proces) Then ProcessClose($proces) EndIf Next Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit Link to comment Share on other sites More sharing options...
ghostofdeath Posted May 19, 2007 Author Share Posted May 19, 2007 (edited) EDIT: TROUBLE BOUND You can use _FireReadToArray if you want to read ANY file to an array. In this way you can write a plaintext file (file extension is up to you), then do something like the following: Dim $a[1] _FileReadToArray("c:\myfile",$a) For $loop = 0 to $a[0] ; <-- The 0'th position of the array will tell how many lines are read ; <-- do whatever you want to the process Next Also... EXTENSIVE Process info (and a LOT of other computer information) can be retrieved easily by using the functions in CompInfo.au3: http://www.autoitscript.com/forum/index.ph...st&id=12096How can i use the func filereadtoarray? i dun have that func here Oo Edited May 19, 2007 by ghostofdeath Link to comment Share on other sites More sharing options...
Shevilie Posted May 19, 2007 Share Posted May 19, 2007 EDIT: TROUBLE BOUNDHow can i use the func filereadtoarray? i dun have that func here Oo#include <Array.au3> Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit Link to comment Share on other sites More sharing options...
ghostofdeath Posted May 19, 2007 Author Share Posted May 19, 2007 anyone knows if it force the process to close? like /f processkill dos command? command? Link to comment Share on other sites More sharing options...
Golbez Posted May 19, 2007 Share Posted May 19, 2007 anyone knows if it force the process to close? like /f processkill dos command? command?use the help file.... Link to comment Share on other sites More sharing options...
herewasplato Posted May 19, 2007 Share Posted May 19, 2007 anyone knows if it force the process to close? like /f processkill dos command? command?It seems to force a close - if there is unsaved text in notepad or MS Word, it will close the process without prompting you to save the info... [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
herewasplato Posted May 19, 2007 Share Posted May 19, 2007 (edited) use the help file....I did not see that question answered in the help file. Maybe I missed it or maybe you were thinking about the info discussed under WinClose/WinKill. Edited May 19, 2007 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Golbez Posted May 19, 2007 Share Posted May 19, 2007 I did not see that question answered in the help file. Maybe I missed it or maybe you were thinking about the info discussed under WinClose/WinKill.processclose will do what you want. its as if you went into the task manager and ended the process. Link to comment Share on other sites More sharing options...
SadBunny Posted May 19, 2007 Share Posted May 19, 2007 A easier way to loop an array is like this For $proces In $process If ProcessExists($proces) Then ProcessClose($proces) EndIf Next Except for that in this case it will have the same error that my code had, namely that it includes ALL elements, which you don't want for a _FileReadToArray result because the 0th element is useless for the rest of the function (in this case you will be trying to kill the process called "17" if you have 17 processes. If you change my For command to For $loop = 1 instead of For $loop = 0 like I did in my previous post, you will have the right list. This cannot be done in this case with For ... In ... with a _FileReadToArray output. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
ghostofdeath Posted May 19, 2007 Author Share Posted May 19, 2007 I did it .. my final code is that: #include <File.au3> While 1 Opt("TrayIconHide",1) Dim $process[1] _FileReadToArray("prcss.dll",$process) for $x=0 to 522 If ProcessExists($process[$x]) Then ProcessClose($process[$x]) EndIf Next WEnd Link to comment Share on other sites More sharing options...
herewasplato Posted May 19, 2007 Share Posted May 19, 2007 (edited) try Opt("TrayIconHide", 1) #include <File.au3> Dim $process[1] While 1 _FileReadToArray("prcss.dll", $process) For $x = 0 To 522 If ProcessExists($process[$x]) Then ProcessClose($process[$x]) EndIf Next WEnd Edited May 19, 2007 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
ghostofdeath Posted May 19, 2007 Author Share Posted May 19, 2007 Yea.. now its fine thanks for everybody Link to comment Share on other sites More sharing options...
herewasplato Posted May 19, 2007 Share Posted May 19, 2007 I originally had "_FileReadToArray("prcss.dll", $process)" outside of the loop, but putting it inside the loop will allow you to edit/save/use the "text file" while the script is running. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
saltedpotato Posted August 14, 2013 Share Posted August 14, 2013 (edited) you can make it as simple as this: to close all process of notepad while ProcessExists("notepad.exe") ProcessClose("notepad.exe") WEnd Edited August 14, 2013 by saltedpotato Link to comment Share on other sites More sharing options...
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