SuperDOS Posted July 25, 2014 Share Posted July 25, 2014 (edited) Hi, I'm trying to add a section in a script that closes several processes before continue. This is what I got: Local $tasks[3] = ["calc.exe", "notepad.exe", "winword.exe"] Local $process = "" For $i = 0 to UBound($tasks) - 1 $process = ProcessList($tasks[$i]) msgbox(0,'','Closing ' & $process[1][0]) ProcessClose($process[1][1]) Next Works great but all three processes must be started or the script will fail since ProcessList doesn't get anything returned if a process isn't running. So I get: Array variable has incorrect number of subscripts or subscript dimension range exceeded. Is there any other way to solve this problem? Have searched but not found anything useful. Thanks Edited July 25, 2014 by SuperDOS Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 25, 2014 Moderators Share Posted July 25, 2014 (edited) How about using ProcessList: #include <Array.au3> $aList = ProcessList() For $i = 1 To $aList[0][0] If $aList[$i][0] = "calc.exe" Then ProcessClose($aList[$i][0]) Next Edit: If you have a bunch to look at, you could do a switch: #For $i = 1 To $aList[0][0] Switch $aList[$i][0] Case "calc.exe", "notepad.exe", "winword.exe" ProcessClose($aList[$i][0]) EndSwitch Next Edited July 25, 2014 by JLogan3o13 232showtime 1 "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! Link to comment Share on other sites More sharing options...
SuperDOS Posted July 25, 2014 Author Share Posted July 25, 2014 $aList = ProcessList() For $i = 1 To $aList[0][0] Switch $aList[$i][0] Case "calc.exe", "notepad.exe", "winword.exe" ProcessClose($aList[$i][0]) EndSwitch This did the trick! Thanks! Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 25, 2014 Moderators Share Posted July 25, 2014 Glad to help "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! Link to comment Share on other sites More sharing options...
SuperDOS Posted July 25, 2014 Author Share Posted July 25, 2014 BTW if I want to store the different processes in a variable and to use like $tasks = """calc.exe"", ""notepad.exe"", ""winword.exe""" $aList = ProcessList() For $i = 1 To $aList[0][0] Switch $aList[$i][0] Case $tasks ProcessClose($aList[$i][0]) EndSwitch Next how can I get it to work? Link to comment Share on other sites More sharing options...
careca Posted July 25, 2014 Share Posted July 25, 2014 (edited) For a string like this: $tasks = "calc.exe, notepad.exe, winword.exe" #include <Array.au3> $tasks = "calc.exe, notepad.exe, winword.exe" $TaskSplit = StringSplit($tasks, ", ", 1) ;_ArrayDisplay($TaskSplit) $ProcList = ProcessList() ;_ArrayDisplay($ProcList) For $T = 1 To $TaskSplit[0] For $P = 1 To $ProcList[0][0] If $TaskSplit[$T] = $ProcList[$P][0] Then ConsoleWrite('Found: ' & $TaskSplit[$T] & ' | ' & $ProcList[$P][0] & @CRLF) ProcessClose($ProcList[$P][0]) EndIf Next Next PS: can be changed for different string format Edited July 25, 2014 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
232showtime Posted July 26, 2014 Share Posted July 26, 2014 How about using ProcessList: #include <Array.au3> $aList = ProcessList() For $i = 1 To $aList[0][0] If $aList[$i][0] = "calc.exe" Then ProcessClose($aList[$i][0]) Next Edit: If you have a bunch to look at, you could do a switch: #For $i = 1 To $aList[0][0] Switch $aList[$i][0] Case "calc.exe", "notepad.exe", "winword.exe" ProcessClose($aList[$i][0]) EndSwitch Next nice now I fully understand the switch func. thanks... :thumbsup: ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
SuperDOS Posted July 28, 2014 Author Share Posted July 28, 2014 For a string like this: $tasks = "calc.exe, notepad.exe, winword.exe" #include <Array.au3> $tasks = "calc.exe, notepad.exe, winword.exe" $TaskSplit = StringSplit($tasks, ", ", 1) ;_ArrayDisplay($TaskSplit) $ProcList = ProcessList() ;_ArrayDisplay($ProcList) For $T = 1 To $TaskSplit[0] For $P = 1 To $ProcList[0][0] If $TaskSplit[$T] = $ProcList[$P][0] Then ConsoleWrite('Found: ' & $TaskSplit[$T] & ' | ' & $ProcList[$P][0] & @CRLF) ProcessClose($ProcList[$P][0]) EndIf Next Next PS: can be changed for different string format Sorry get an error running this. How come I can't use a variable with case? Link to comment Share on other sites More sharing options...
careca Posted July 28, 2014 Share Posted July 28, 2014 (edited) I mostly don't use case, it's not my style. What error? is the string the one in the example? Edited July 28, 2014 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
SuperDOS Posted July 28, 2014 Author Share Posted July 28, 2014 ok, well I noticed that it had to do when copying the text of your code to the editor. The tab-character before some of the lines wasn't converted right, after removing the "illegal characters" it works. Thanks! Link to comment Share on other sites More sharing options...
careca Posted July 28, 2014 Share Posted July 28, 2014 (edited) Not sure where you're getting at but, as i said, the code can be adjusted to remove "tab", or other characters, it's just an example, proof of concept so to speak. The script assumes ', ' comma with space as a separator character, but if needed, can assume only the comma ',' Then the string would have to be: $tasks = "calc.exe,notepad.exe,winword.exe" but it would work. Edited July 28, 2014 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 28, 2014 Moderators Share Posted July 28, 2014 Sorry get an error running this. How come I can't use a variable with case? You can use a variable with case, but in this instance AutoIt sees your variable as calc.exe, notepad.exe, winword.exe. This will never match a process name, obviously, so you would have to split it. If you want a list of three or four processes, and want them in variables, you would have to do something like this: $calc = "calc.exe" $notepad = "notepad.exe" $word = "winword.exe" $aList = ProcessList() For $i = 1 To $aList[0][0] Switch $aList[$i][0] Case $calc ProcessClose($calc) Case $notepad ProcessClose($notepad) Case $word ProcessClose($word) EndSwitch Next 232showtime 1 "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! 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