Created
October 15, 2021 07:16
-
-
Save malys/85ea0916318de473384715bdfc722a70 to your computer and use it in GitHub Desktop.
[Suspend process] suspend and resume process #windows #dos #batch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem ================================================================ | |
rem To suspend a process, use the following command: | |
rem suspend.cmd | |
rem =========================== | |
rem To resume a process, use the following command: | |
rem suspend.cmd resume | |
rem ================================================================ | |
rem Process to suspend or resume | |
set var="notepad.exe" "firefox.exe" | |
set maxAttempt=5 | |
if [%1]==[] ( | |
set params= | |
set action=Suspend | |
) else ( | |
set params=-r | |
set action=Resume | |
) | |
echo ================================================================ | |
echo %action%% mode | |
echo ================================================================ | |
setlocal ENABLEDELAYEDEXPANSION | |
for %%i in (%var%) do ( | |
set attempt=0 | |
set process=="%%~i" | |
call :Process !process! | |
) | |
endlocal | |
exit | |
:Process | |
set processName=%~1 | |
set /A attempt+=1 | |
if "!attempt!" GTR "%maxAttempt%" ( | |
echo Max attempts reached ^(%maxAttempt%^)^^! | |
) else ( | |
echo Attempt n !attempt! to find "!processName!" ... | |
C:\Windows\System32\timeout.exe 5 /NoBreak>Nul | |
QProcess "!processName!">Nul 2>&1||GoTo :Process | |
pssuspend64.exe %params% -nobanner "!processName!" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment