DOS command/windows kill掉指定的进程

阅读更多
::统计D盘movie目录下文件总数及D盘剩余容量
@echo off

for /f %%i in ('dir /s *.*^|find /i "个文件"') do set num=%%i 

echo.

echo 文件数量统计结果:

echo.

echo D:\movie目录下有 %num% 个文件

echo.

echo.

echo D盘空间统计结果:

echo.

echo 盘符  剩余空间(字节)  分区大小(字节)

wmic logicaldisk where caption="D:" get size,freespace,caption | findstr /v /i "caption"

pause>nul 

:: 查找当前文件夹下有多少个java文件 dir .\*.java /b /s | find /v /c "$$$$"



taskkill.bat
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

你可能感兴趣的:(windows,DOS)