我运行了这个批处理文件:
:START
FOR /f "tokens=2 delims=," %%a in ('typeperf "\processor(_Total)\%% Processor Time" -SC 1 -y ^|find ":" ') DO
(set "var=%%~na"
IF var>=30
(netsh interface teredo set state disabled
netsh interface 6to4 set state disabled
netsh interface isatap set state disabled )
IF var<30
( netsh interface teredo set state client
netsh interface 6to4 set state enabled
netsh interface isatap set state enabled
) )
goto START
我希望此程序持续扫描CPU使用百分比,并将该值存储在整数&#39;
中。现在如果CPU使用率超过30%,我想禁用IPv6。如果CPU使用率降至30%,我想启用IPv6。我写了上面的代码,但它没有用。你能说出问题出在哪里吗?
答案 0 :(得分:0)
如果您的netsh命令正确,那么这可能对您有用:
@echo off
:START
FOR /f "tokens=2 delims=," %%a in ('typeperf "\processor(_Total)\%% Processor Time" -SC 1 -y ^|find ":" ') DO (
echo CPU is at %%a %%
IF %%~na GTR 30 (
echo disabling
netsh interface teredo set state disabled
netsh interface 6to4 set state disabled
netsh interface isatap set state disabled
) else (
echo enabling
netsh interface teredo set state client
netsh interface 6to4 set state enabled
netsh interface isatap set state enabled
)
)
echo waiting
timeout /t 5 /nobreak >nul
goto :START
答案 1 :(得分:0)