此命令在管理员 CMD 中显示引导管理器等待标准操作系统自动引导的秒数:
bcdedit /enum | find "timeout"
我想以秒为单位将输出值批量压入环境变量吗?但它不是这样工作的:
for /f "tokens=2*" %%a in ('bcdedit /enum | find "timeout"') do set "value=%%a"
echo %value%
pause
exit
有谁知道如何设置令牌命令?
此命令在管理员 CMD 中显示引导管理器等待标准操作系统自动引导的秒数:
bcdedit /enum | find "timeout"
我想以秒为单位将输出值批量压入环境变量吗?但它不是这样工作的:
for /f "tokens=2*" %%a in ('bcdedit /enum | find "timeout"') do set "value=%%a"
echo %value%
pause
exit
有谁知道如何设置令牌命令?
您必须在 | 之前使用转义字符“^” 而且脚本必须以管理员身份运行,因为 bcdedit 命令需要管理员权限。
@echo off
net session >nul 2>&1 || (powershell start -verb runas '"%~0"' &exit /b)
for /f "tokens=2*" %%a in ('bcdedit /enum ^| find /i "timeout"') do set "value=%%a"
echo %value%
pause
exit
我首先要确保我只在适当的标识符下输出bcdedit{bootmgr}
信息, . 然后我不会只使用英语字符串timeout
。
从cmd窗口“以管理员身份运行”:
For /F "Delims=" %G In ('%SystemRoot%\System32\bcdedit.exe /Enum {bootmgr} 2^>NUL ^| %SystemRoot%\System32\findstr.exe /RC:"[ ][ ]*[0123456789][0123456789]*$"') Do @For %H In (%G) Do @Set "$=%H"
@Echo Off
SetLocal EnableExtensions
Set "$=" & For /F "Delims=" %%G In (
'%SystemRoot%\System32\bcdedit.exe /Enum {bootmgr} 2^>NUL^
^|%SystemRoot%\System32\findstr.exe /RC:"[ ][ ]*[0123456789][0123456789]*$'
) Do For %%H In (%%G) Do Set "$=%%H"
在此示例中,从成功结果开始的秒数应保存为可访问为 的变量的字符串值%$%
。