Jump to content

Close list of processes


Recommended Posts

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 by SuperDOS
Link to comment
Share on other sites

  • Moderators

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 by JLogan3o13

"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

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

 

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: :thumbsup: :thumbsup:

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

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

I mostly don't use case, it's not my style.

What error? is the string the one in the example?

Edited 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

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

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

  • Moderators

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

"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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...