此命令在管理 CMD 中显示引导管理器等待标准操作系统自动引导的秒数:
bcdedit /enum | find "timeout"
我是否想将输出值以秒为单位批量压入环境变量中?但它不是这样工作的:
for /f "tokens=2*" %%a in ('bcdedit /enum | find "timeout"') do set "value=%%a"
echo %value%
pause
exit
有谁知道如何设置令牌命令?
答案 0 :(得分:1)
您必须在 | 之前使用转义字符“^”并且脚本必须以管理员身份运行,因为 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
答案 1 :(得分:0)
我首先要确保我只在适当的标识符 $4c00
下输出 bcdedit 信息。那么我不会只使用英文字符串 {bootmgr}
。
从 cmd 窗口“以管理员身份运行”:
timeout
或者来自 windows batch-file '以管理员身份运行':
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"
访问的变量的字符串值。