【问题标题】:system("bcdedit /set safeboot") does not set windows to safebootsystem("bcdedit /set safeboot") 未将 Windows 设置为安全启动
【发布时间】:2018-06-02 17:03:18
【问题描述】:

这是带有命令的 c++ 代码,用于在网络模式下以安全启动运行 Windows 并重新启动的命令,此代码仅在 32 位操作系统中运行,但在 64 位操作系统中仅会发生重启,但不会在安全启动模式下发生。

[注意]:我在管理模式下运行应用程序。

system("bcdedit /set safeboot network  > Out.txt");
system("shutdown -r -f -t 0");

还有ShellExecute()

ShellExecute(0, L"open", L"cmd.exe", L"/C bcdedit /set safeboot network > Out.txt", 0, SW_HIDE);
ShellExecute(0, L"open", L"cmd.exe", L"/C shutdown -r -f -t 0 > Out.txt", 0, SW_HIDE);

我尝试像在管理模式下手动打开 CMD

c:\WINDOWS\system32>bcdedit /set safeboot network
The Operation completed successfully.
c:\WINDOWS\system32>shutdown -r -f -t 0

手动它可以工作(在安全启动中运行),但是当我尝试通过代码重新启动 Windows 时,但不在安全启动中。

如何让这个在 32 位和 64 位操作系统上都能工作?

【问题讨论】:

    标签: c++ cmd 32bit-64bit bcdedit


    【解决方案1】:

    您是否以管理员身份使用 system() 调用运行您的程序?如果你不这样做,我不会指望这个电话会成功。

    【讨论】:

      【解决方案2】:

      > Out.txt 可能不是有效参数请注意,system 不是用于重定向标准 io 的命令 shell 解释器。如果您想获得输出,那么最好使用 CreateProcess 或一些包装器(例如 boost.Process)手动重定向它们。

      【讨论】:

        【解决方案3】:

        我在64 位机上执行程序。 bcdedit.exe 文件存在于C:\Windows\System32 虽然C:\Windows\System32 在系统路径中,但在x86 进程中受File System Redirector 的约束。这意味着C:\Windows\System32 实际上解析为C:\Windows\SysWOW64

        C:\Windows\SysWOW64中没有32位版本的bcdedit.exe

        解决方法是更改​​目标AnyCPUx64.

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-12-15
          • 2021-09-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-09-10
          • 2012-09-11
          • 1970-01-01
          相关资源
          最近更新 更多