RestrictedUser Posted March 12, 2019 Share Posted March 12, 2019 (edited) Hello AutoIt Scriptwriters❤️👋 I had searched many times about this topic's title but i didn't found any useful information to solve my question I want to close multiple processes in one string by Array I want to be similar to this: _Process() Func _Process() While 1 $iPID = ("notepad.exe", "word.exe", "firefox.exe", "chrome.exe") If ProcessExists($iPID) Then ProcessClose($iPID) Else MsgBox(64, "", "Favorite processes aren't exist") ExitLoop WEnd Exit EndFunc Edited March 12, 2019 by Colduction Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 12, 2019 Share Posted March 12, 2019 @Colduction Global $arrProcess[4] = ["notepad.exe", "word.exe", "firefox.exe", "chrome.exe"] For $i = 0 To UBound($arrProcess) - 1 Step 1 If ProcessExists($arrProcess[$i]) Then ConsoleWrite("Closing process '" & $arrProcess[$i] & "'" & @CRLF) If ProcessClose($arrProcess[$i]) Then ConsoleWrite("Process closed." & @CRLF) Else ConsoleWrite("Cannot close the process." & @CRLF) EndIf Else ConsoleWrite("The process '" & $arrProcess[$i] & "' doesn't exist." & @CRLF) EndIf Next You can find more about arrays here, and, youo don't need to make all those loops. Subz and RestrictedUser 1 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Subz Posted March 12, 2019 Share Posted March 12, 2019 (edited) Slightly modified version, to close all instances: Global $aProcess Global $arrProcess[4] = ["notepad.exe", "word.exe", "firefox.exe", "chrome.exe"] For $i = 0 To UBound($arrProcess) - 1 Step 1 If ProcessExists($arrProcess[$i]) Then ConsoleWrite('Closing process "' & $arrProcess[$i] & '"' & @CRLF) $aProcess = ProcessList($arrProcess[$i]) For $j = 1 To $aProcess[0][0] If ProcessClose($aProcess[$j][1]) Then ConsoleWrite(" - Instance: " & $j & " closed." & @CRLF) Else ConsoleWrite(" - Instance: " & $j & " cannot be closed." & @CRLF) EndIf Next Else ConsoleWrite('The process "' & $arrProcess[$i] & '"' & " doesn't exist." & @CRLF) EndIf Next Edited March 12, 2019 by Subz FrancescoDiMuro and RestrictedUser 1 1 Link to comment Share on other sites More sharing options...
RestrictedUser Posted March 12, 2019 Author Share Posted March 12, 2019 2 hours ago, FrancescoDiMuro said: don't need to make all those loops Thanks for answering to my Question👍❤️ But infinite loop needed!, because i want check if that process exists, then close that! Link to comment Share on other sites More sharing options...
RestrictedUser Posted March 12, 2019 Author Share Posted March 12, 2019 1 hour ago, Subz said: Slightly modified version, to close all instances: Global $aProcess Global $arrProcess[4] = ["notepad.exe", "word.exe", "firefox.exe", "chrome.exe"] For $i = 0 To UBound($arrProcess) - 1 Step 1 If ProcessExists($arrProcess[$i]) Then ConsoleWrite('Closing process "' & $arrProcess[$i] & '"' & @CRLF) $aProcess = ProcessList($arrProcess[$i]) For $j = 1 To $aProcess[0][0] If ProcessClose($aProcess[$j][1]) Then ConsoleWrite(" - Instance: " & $j & " closed." & @CRLF) Else ConsoleWrite(" - Instance: " & $j & " cannot be closed." & @CRLF) EndIf Next Else ConsoleWrite('The process "' & $arrProcess[$i] & '"' & " doesn't exist." & @CRLF) EndIf $iInstance = 1 Next Thanks bro❤️ Link to comment Share on other sites More sharing options...
RestrictedUser Posted March 12, 2019 Author Share Posted March 12, 2019 2 hours ago, FrancescoDiMuro said: You can find more about arrays here Thanks for helping!❤️❤️ Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 12, 2019 Share Posted March 12, 2019 @Colduction You're welcome RestrictedUser 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette 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