日期:2014-05-16 浏览次数:20721 次
wmic process where "name='cmd.exe' and processid!=1100" call terminate taskkill /f /im cmd.exe /fi "pid ne 1100" taskkill /fi "pid ne 1100" /fi "pid ne 1200" /im cmd.exe
假设需要Sleep 10秒,就可以这样写: SET SLEEP=ping 127.0.0.1 -n %SLEEP% 11 > nul 不过更奇的办法,不依赖任何外部命令,纯用批处理实现Sleep,能精确到0.01秒,这是个2秒的例子: @ECHO OFF SETLOCAL EnableExtensions CALL :ProcDelay 200 ECHO %TIME% GOTO :EOF :ProcDelay delayMSec_ SETLOCAL EnableExtensions FOR /f "tokens=1-4 delims=:. " %%h IN ("%TIME%") DO SET start_=%%h%%i%%j%%k :_procwaitloop FOR /f "tokens=1-4 delims=:. " %%h IN ("%TIME%") DO SET now_=%%h%%i%%j%%k SET /a diff_=%now_%-%start_% IF %diff_% LSS %1 GOTO _procwaitloop ENDLOCAL & GOTO :EOF :EOF
@ECHO OFF ::将所有进程信息列入list.txt文件里面(这里默认当前目录) tasklist > list.txt ::从list.txt文件里查找notepad.exe这个进程 find /i "notepad.exe" list.txt ::如果进程不存在,执行start处的代码;反之执行杀掉进程 if "%errorlevel%"=="0" ( ::杀掉进程 ::taskkill /f /im notepad.exe wmic process where name="notepad.exe" terminate echo kill the notpad.exe completed. > list.txt ) else ( goto start ) :start cls echo no this process... SET SLEEP=ping 127.0.0.1 -n %SLEEP% 2 > nul ::end exit