我正在尝试使用此命令让我的电脑休眠
system("C:\\Windows\\System32\\psshutdown -d -t 0");
如果我使用 cmd 它工作正常,但是当我在 cpp 中运行它时,我得到了这个
'C:\Windows\System32\psshutdown' is not recognized as an internal or external command, operable program or batch file.
在 64 位 Windows 上运行的 32 位应用程序将置于 文件系统重定向 之下。因此,如果您的应用程序是 32 位应用程序,调用
system("C:\\Windows\\System32\\psshutdown -d -t 0");
将在 psshutdown.exe
中查找 C:\Windows\SysWOW64
并失败。你有一些解决方案:
使用 Sysnative 访问真正的 System32 文件夹:
system(R"(C:\Windows\Sysnative\psshutdown -d -t 0)");
明确关闭文件系统重定向(一般应避免)
或更好将您的应用程序重新编译为 64 位应用程序