Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何将CPU使用率值作为整数获取?_Batch File_Command_Cpu Usage_Netsh - Fatal编程技术网

Batch file 如何将CPU使用率值作为整数获取?

Batch file 如何将CPU使用率值作为整数获取?,batch-file,command,cpu-usage,netsh,Batch File,Command,Cpu Usage,Netsh,我运行了此批处理文件: :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 i

我运行了此批处理文件:

: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
:开始
对于/f“tokens=2 delims=,”%%a in('typeperf“\processor(\u Total)\%%processor Time)-SC 1-y^ find:“')DO
(设置“var=%%~na”
如果var>=30
(netsh接口teredo设置状态已禁用
netsh接口6to4设置状态已禁用
netsh接口(设置状态已禁用)

如果var如果您的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

还有一种方法-使用LOGMAN,它依赖于与

使用这种方法,您将不需要运行/循环批处理文件-在下面的代码完成后,任务将自动启动

但您需要创建两个额外的
.bat
文件来启用和禁用IPv6(在本例中为disable6.bat和enable6.bat)。或者至少创建一个额外的bat,该bat接受参数并使用logman的
-target
键(logman和SCHTASKS都需要管理员权限):

@echo关闭
SCHTASKS/create/tn disable/tr“C:\disable.bat”/sc ONCE/sd 01/01/1910/st 00:00
logman stop high_cpu 2>nul和logman delete high_cpu
logman创建警报高\u cpu-th“\处理器(\u总计)\%%处理器时间>30”-tn“禁用”
logman启动高\u cpu
SCHTASKS/create/tn enable/tr“C:\enable6.bat”/sc ONCE/sd 01/01/1910/st 00:00
logman停止低cpu 2>nul和logman删除低cpu 2>nul

logman create alert low\u cpu-th“\Processor(\u Total)\%%Processor Time为特定网卡禁用IPV6是什么意思?我不认为
netsh interface 6to4 set state disabled
就是禁用。
@echo off


SCHTASKS /create /tn disable /tr "C:\disable.bat" /sc ONCE /sd 01/01/1910 /st 00:00 
logman stop high_cpu 2>nul & logman delete high_cpu 
logman create alert high_cpu -th "\Processor(_Total)\%% Processor Time>30" -tn "disable"
logman start high_cpu



SCHTASKS /create /tn enable /tr "C:\enable6.bat" /sc ONCE /sd 01/01/1910 /st 00:00
logman stop low_cpu 2>nul & logman delete low_cpu 2>nul  
logman create alert low_cpu -th "\Processor(_Total)\%% Processor Time<30" -tn "enable" 
logman start low_cpu