Jump to content
Sign in to follow this  
RestrictedUser

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

Share this post


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

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


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

Share this post


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

Share this post


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❤️

Share this post


Link to post
Share on other sites

@Colduction

You're welcome :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...