windows - how do I kill all cmd.exe except the one currently running from batch? -


the past few days have been working on script thought rather easy seems not, , understand why. problem how around it.

the batch script need explained:

i have script runs in cmd.exe bunch of things moving huge amount of files location another. lets call movefile.cmd. script works, happens stop (very - lets not go why , script). important script runs, idea here create batch exits cmd.exe , re-opens script each hour or so. lets call script restartcmd.bat

sounds easy this:

@echo off  :loop  start c:\script\movefile.cmd   timeout /nobreak /t 3600  taskkill cmd.exe  goto loop 

but doesn't work because new script runs in cmd.exe, kill process well.

what i've tried:

so made copy of cmd.exe , renamed dontkillthis.exe. run dontkillthis.exe , open restardcmd.bat dontkillthis.exe - works perfectly! need able dobbleclick script instead of doing that. why? because supposed easy possible , want restartcmd.bat in startup folder.

i've been looking @ ideas of getting exact process id of cmd.exe , shutting dontkillthis.exe remain, can't seem nail it. tried thats written in here how kill batch files except 1 running , can't work.

i'm not sure if i'm being confused or if bit hard this.

i'd appreciate here.

best regards

mo

first you'll need pid of current cmd instance. topic has been discussed here . offer solution - getcmdpid.bat

and here's script (getcmdpid should in same directory ):

@echo off  call getcmdpid set "current_pid=%errorlevel%"  /f "skip=3 tokens=2 delims= " %%a in ('tasklist /fi "imagename eq cmd.exe"') (     if "%%a" neq "%current_pid%" (         taskkill /pid %%a /f >nul 2>nul     ) ) 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -