Termination of Non-essential Processes Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Termination of Non-essential Processes

Post by Alexander2 » 27 Sep 2021, 13:58

Does anyone know whether it is possible to terminate all currently running processes which are not essential to the system? (This includes the user’s applications and processes like Windows Compatibility Telemetry.)
I need this to be able to free the system’s resources instantly and improve performance.

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Termination of Non-essential Processes

Post by mikeyww » 27 Sep 2021, 14:16

WinGet can get you a list. You can then use Process to close whichever you like.

Code: Select all

DetectHiddenWindows, On
WinGet, win, List
list =
Loop, %win% {
 WinGet, proc, ProcessPath, % "ahk_id " win%A_Index%
 list .= "`n" proc
}
list := SubStr(list, 2)
Sort, list, U
MsgBox, 64, Processes, %list%
Or:

Code: Select all

DetectHiddenWindows, On
WinGet, win, List
list =
Loop, %win% {
 WinGet, proc, ProcessName, % "ahk_id " win%A_Index%
 SplitPath, proc,,,, fnBare
 list .= fnBare > "" ? "`n" fnBare : ""
}
list := SubStr(list, 2)
Sort, list, U
MsgBox, 64, Processes, %list%
For each, proc in StrSplit(list, "`n")
 If proc not in AutoHotkey ; Adjust as needed
;  Process, Close, %proc%.exe
:arrow: Use at your own risk!

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Termination of Non-essential Processes

Post by Alexander2 » 28 Sep 2021, 08:12

mikeyww wrote:
27 Sep 2021, 14:16
WinGet can get you a list. You can then use Process to close whichever you like.

Code: Select all

DetectHiddenWindows, On
WinGet, win, List
list =
Loop, %win% {
 WinGet, proc, ProcessPath, % "ahk_id " win%A_Index%
 list .= "`n" proc
}
list := SubStr(list, 2)
Sort, list, U
MsgBox, 64, Processes, %list%
Or:

Code: Select all

DetectHiddenWindows, On
WinGet, win, List
list =
Loop, %win% {
 WinGet, proc, ProcessName, % "ahk_id " win%A_Index%
 SplitPath, proc,,,, fnBare
 list .= fnBare > "" ? "`n" fnBare : ""
}
list := SubStr(list, 2)
Sort, list, U
MsgBox, 64, Processes, %list%
For each, proc in StrSplit(list, "`n")
 If proc not in AutoHotkey ; Adjust as needed
;  Process, Close, %proc%.exe
:arrow: Use at your own risk!
Thank you. This is a convenient way to get a list of running processes. What is the purpose of the following lines in the second script?

Code: Select all

For each, proc in StrSplit(list, "`n")
If proc not in AutoHotkey
Process, Close, %proc%.exe

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Termination of Non-essential Processes

Post by mikeyww » 28 Sep 2021, 08:17

If you want to close some processes, this is one way to achieve it. It loops through each process in the list. If the process is not one in a list of specified processes, then the process is closed.

If... in

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Termination of Non-essential Processes

Post by Alexander2 » 29 Sep 2021, 08:18

I have replaced “AutoHotkey” with “list” in the given script according to your instruction. Will the script now work as intended?

Code: Select all

DetectHiddenWindows, On
WinGet, win, List
list =
Loop, %win% {
 WinGet, proc, ProcessName, % "ahk_id " win%A_Index%
 SplitPath, proc,,,, fnBare
 list .= fnBare > "" ? "`n" fnBare : ""
}
list := SubStr(list, 2)
Sort, list, U
MsgBox, 64, Processes, %list%
For each proc in StrSplit(list, "`n")
If proc not in list
Process, Close, %proc%.exe

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Termination of Non-essential Processes  Topic is solved

Post by mikeyww » 29 Sep 2021, 10:16

On line 13, I think you would want to name the specific processes that you want to exclude, instead of excluding none of them. The list of processes to exclude can be a literal comma-separated string (see documentation as noted), or a variable name flanked by %. Of course, the answer to "Will this work?" is,.... try it! :) (But I recommend fixing your script first.)

A starting point: close all of the programs that you normally run. Look in Windows Task Manager to see what is left. Make a list of those processes, separated by commas. You can use that as your exclusion list. This particular script omits the file extension in the list, and adds it back when it closes each process.

An alternative approach to exclusions is to determine whether each window is visible, and just close those. That is safer, because you might otherwise end up closing various services and Windows programs that might be important. The following provides an example of identifying visible windows.

viewtopic.php?p=415031#p415031

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Termination of Non-essential Processes

Post by Alexander2 » 01 Oct 2021, 06:50

mikeyww wrote:
29 Sep 2021, 10:16
On line 13, I think you would want to name the specific processes that you want to exclude, instead of excluding none of them. The list of processes to exclude can be a literal comma-separated string (see documentation as noted), or a variable name flanked by %. Of course, the answer to "Will this work?" is,.... try it! :) (But I recommend fixing your script first.)

A starting point: close all of the programs that you normally run. Look in Windows Task Manager to see what is left. Make a list of those processes, separated by commas. You can use that as your exclusion list. This particular script omits the file extension in the list, and adds it back when it closes each process.

An alternative approach to exclusions is to determine whether each window is visible, and just close those. That is safer, because you might otherwise end up closing various services and Windows programs that might be important. The following provides an example of identifying visible windows.

viewtopic.php?p=415031#p415031
Thank you. Ii is easy to make a list of unnecessary processes displayed in Task Manager and then terminate them with the use of AutoHotkey. I needed this in order to end unnecessary processes like Compatibility Telemetry which use system resources.

Post Reply

Return to “Ask for Help (v1)”