系统( "bcdedit /set safeboot" ) 未将窗口设置为安全启动

system("bcdedit /set safeboot") does not set windows to safeboot

本文关键字:窗口 设置 安全 启动 bcdedit set safeboot 系统      更新时间:2023-10-16

这是带有命令的c 代码,命令命令在safeboot中使用网络模式和重新启动,此代码仅在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:WINDOWSsystem32>bcdedit /set safeboot network
The Operation completed successfully.
c:WINDOWSsystem32>shutdown -r -f -t 0

手动工作(在Safeboot中运行),但是当我尝试重新启动代码窗口时,但不在Safeboot中。

如何使这项工作既有32位和64位操作系统?

您是否使用System()调用作为管理员来运行程序?如果您不这样做,我不会期望这个电话会成功。

> Out.txt可能不是有效的参数。如果您想获取输出,那么最好使用CreateProcess或一些包装器(例如bost.process.proces.process)手动重定向它们。

上午在64位计算机上执行该程序。bcdedit.exe文件存在于C:WindowsSystem32中,尽管C:WindowsSystem32处于系统路径中,但在x86进程中受文件系统重定向器的约束。这意味着C:WindowsSystem32实际上可以解决C:WindowsSysWOW64

C:WindowsSysWOW64中没有32 BIT版本

解决方案是更改目标AnyCPUx64.