Jump to content

Close multiple processes in Array


Recommended Posts

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 by Colduction
Link to post
Share on other sites

@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.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to post
Share on other sites

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 by Subz
Link to post
Share on other sites
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 post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...