hulian425
@echo off
set PROCESSNAME=notepad.exe

::First save current pids with the wanted process name
setlocal EnableExtensions EnableDelayedExpansion
set "RETPIDS="
set "OLDPIDS=p"
for /f "TOKENS=1" %%a in (\'wmic PROCESS where "Name=\'%PROCESSNAME%\'" get ProcessID ^| findstr [0-9]\') do (set "OLDPIDS=!OLDPIDS!%%ap")

::Spawn new process(es)
start %PROCESSNAME%
start %PROCESSNAME%
start %PROCESSNAME%

::Check and find processes missing in the old pid list
for /f "TOKENS=1" %%a in (\'wmic PROCESS where "Name=\'%PROCESSNAME%\'" get ProcessID ^| findstr [0-9]\') do (
if "!OLDPIDS:p%%ap=zz!"=="%OLDPIDS%" (set "RETPIDS=/PID %%a !RETPIDS!")
)

::Kill the new threads (but no other)
taskkill %RETPIDS% /T > NUL 2>&1
endlocal

 

分类:

技术点:

相关文章:

  • 2021-12-19
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2021-12-16
  • 2021-08-25
  • 2022-03-06
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2022-02-06
  • 2022-12-23
  • 2021-11-27
  • 2022-03-09
  • 2022-01-21
相关资源
相似解决方案