Skip to content

Instantly share code, notes, and snippets.

@MRsoymilk
Created August 8, 2023 07:14
Show Gist options
  • Select an option

  • Save MRsoymilk/a43302b9fa4f0737ba118f11e0a071f7 to your computer and use it in GitHub Desktop.

Select an option

Save MRsoymilk/a43302b9fa4f0737ba118f11e0a071f7 to your computer and use it in GitHub Desktop.
bat file, close multiple programs
@echo off
rem This script is used to close multiple programs with specified process names
rem Please enter the process names of the programs you want to close below, enclosed in double quotes and separated by spaces
set processes="notepad.exe" "mspaint.exe" "calc.exe"
rem Use a for loop to traverse each process name, use the taskkill command to forcibly end the process according to the process name, /f parameter means forced closure, /im parameter means filtering according to image name
for %%p in (%processes%) do (
taskkill /f /im %%p
rem Show operation results
if %errorlevel%==0 (
echo Successfully closed %%p
) else (
echo Failed to close %%p, maybe the program was not found or there was no permission
)
)
pause
@echo off
rem This script is used to close multiple programs with specified window titles
rem Please enter the window titles of the programs you want to close below, enclosed in double quotes and separated by spaces
set titles="Notepad" "Paint"
rem Use a for loop to traverse each window title, use the taskkill command to forcibly end the process according to the window title, /f parameter means forced closure, /fi parameter means filtering according to conditions
for %%t in (%titles%) do (
taskkill /f /fi "windowtitle eq %%t"
rem Show operation results
if %errorlevel%==0 (
echo Successfully closed %%t
) else (
echo Failed to close %%t, maybe the program was not found or there was no permission
)
)
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment