Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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
Command line 使用bcdedit编写脚本_Command Line_Command Line Interface_Command Prompt_Bcdedit - Fatal编程技术网

Command line 使用bcdedit编写脚本

Command line 使用bcdedit编写脚本,command-line,command-line-interface,command-prompt,bcdedit,Command Line,Command Line Interface,Command Prompt,Bcdedit,使用ImageX和WIM重建HDD后,BCD有时会损坏。因此,我需要从在命令提示符下无人值守地运行的脚本中重新生成BCD 以下代码在手动输入时执行此操作。我需要帮助来实现自动化(请参阅下面的代码示例): 如上所述,我需要在无人参与的命令提示符下运行它。最后第6条语句“bcdedit.exe/create/d”Microsoft Windows“/application osloader”的输出是新创建的GUID。以下命令中需要此ID 如何将这个新GUID从bcdedit加载到一个可以在以下代码中

使用ImageX和WIM重建HDD后,BCD有时会损坏。因此,我需要从在命令提示符下无人值守地运行的脚本中重新生成BCD

以下代码在手动输入时执行此操作。我需要帮助来实现自动化(请参阅下面的代码示例):

如上所述,我需要在无人参与的命令提示符下运行它。最后第6条语句“bcdedit.exe/create/d”Microsoft Windows“/application osloader”的输出是新创建的GUID。以下命令中需要此ID

如何将这个新GUID从bcdedit加载到一个可以在以下代码中调用的变量

致意
Henrik V.Nielsen

如果其他人也面临同样的问题,我通过添加以下行来解决它

For /F "tokens=2 delims={}" %%i in ('bcdedit.exe') do (set _NEWGUID=%%i)

这是因为文件中只有一个GUID。

有一种更简单的方法

创建新条目时,BCD接受格式为aaaaaaaa-bbbb-cccc-dddd-eeee的所有GUID(位数8-4-4-12

这意味着您可以定义GUID,而不必使用For循环搜索GUID


这是一个基于Henrik代码的解决方案

这将把从BCD创建的GUID放入文本文件,for循环从该文件获取GUID

bootrec.exe /fixmbr
bootsect.exe /nt60 all /force
attrib -h -s C:\boot\BCD
del C:\boot\BCD
bcdedit.exe /createstore c:\boot\bcd.temp
bcdedit.exe /store c:\boot\bcd.temp /create {bootmgr} /d "Windows Boot Manager"
bcdedit.exe /import c:\boot\bcd.temp
bcdedit.exe /set {bootmgr} device partition=C:
bcdedit.exe /timeout 10
attrib -h -s C:\boot\bcd.temp
del c:\boot\bcd.temp
bcdedit.exe /create /d "Microsoft Windows" /application osloader>GUID.txt
For /F "tokens=2 delims={}" %%i in (GUID.txt) do (set _NEWGUID=%%i)
bcdedit.exe /set %_NEWGUID% device partition=C:
bcdedit.exe /set %_NEWGUID% osdevice partition=C:
bcdedit.exe /set %_NEWGUID% path \Windows\system32\winload.exe
bcdedit.exe /set %_NEWGUID% systemroot \Windows
bcdedit.exe /displayorder %_NEWGUID%
迪伦·格拉沙 您的答案有一些错误,我添加了一些增强功能以使其更加完整

@Echo Off
bootrec.exe /fixmbr
bootsect.exe /nt60 C: /force
attrib -h -s C:\boot\BCD
del C:\boot\BCD
attrib -h -s C:\boot\bcd.temp >nul
del C:\boot\bcd.temp >nul
bcdedit /createstore c:\boot\bcd.temp
bcdedit.exe /store c:\boot\bcd.temp /create {bootmgr} /d "Windows Boot Manager"
bcdedit.exe /import c:\boot\bcd.temp
bcdedit.exe /set {bootmgr} device partition=C:
bcdedit.exe /timeout 10
attrib -h -s C:\boot\bcd.temp
del c:\boot\bcd.temp
bcdedit.exe /create /d "Microsoft Windows" /application osloader>GUID.txt
For /F "tokens=2 delims={}" %%i in (GUID.txt) do (set _NEWGUID=%%i)
bcdedit.exe /set {%_NEWGUID%} device partition=C:
bcdedit.exe /set {%_NEWGUID%} osdevice partition=C:
bcdedit.exe /set {%_NEWGUID%} path \Windows\system32\winload.exe
bcdedit.exe /set {%_NEWGUID%} systemroot \Windows
bcdedit.exe /displayorder {%_NEWGUID%}
del guid.txt
cmd

有一种更简单的方法来修复BCD

bcdboot c:\windows 
例如,替换问题中的所有bcdedit命令

有关详细信息,请参见说明

实用程序bcdboot和bootssect可以修复所有引导问题(关于初始引导顺序)


sfc.exe可以修复损坏的系统文件。

您好。我忘了提到操作系统是Win7嵌入式32位的。我正在用WinPE U盘运行脚本。你好,netlord先生,听起来很有趣。下次需要更新脚本时,我将尝试实现。
bcdboot c:\windows