我在公司工作,每天必须手动做一件我愿意自动化的工作
我们必须每隔两小时监视一个进程的任务栏,如果进程没有CPU利用率,那么我们必须将其杀死其他OK 请帮我自动化。
答案 0 :(得分:1)
只需将notepad
更改为您要观看的流程:
@echo off
set "process_name=notepad.exe"
::remoce .exe suffix if there is
set pn=%process_name:.exe=%
setlocal enableDelayedExpansion
set c=0
:: getting three snapshots of CPU usage of the given process
for /f skip^=2^ tokens^=3^ delims^=^" %%p in ('typeperf "\Process(%pn%)\%% Processor Time" -sc 3') do (
set /a counter=counter+1
for /f "tokens=1,2 delims=." %%a in ("%%p") do set "process_snapshot_!counter!=%%a%%b"
)
:: remove rem to see the cpu usage from the three snapshots
rem set process_snapshot_
:: if all three snapshots are less than 0000010 process will be killed
if 1%process_snapshot_1% LSS 10000010 if 1%process_snapshot_2% LSS 10000010 if 1%process_snapshot_3% LSS 10000010 (
tskill %pn%
)