【问题标题】:Executing CMD commands using C++使用 C++ 执行 CMD 命令
【发布时间】:2021-02-19 19:06:57
【问题描述】:

我正在尝试使用此命令让我的电脑进入睡眠状态

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.

【问题讨论】:

    标签: c++ windows cmd 32bit-64bit wow64


    【解决方案1】:

    在 WOW64 上运行的 32 位应用程序将放在 file system redirection 下。因此,如果您的应用程序是 32 位应用程序,则调用 system("C:\\Windows\\System32\\psshutdown -d -t 0"); 将在 C:\Windows\SysWOW64 中查找 psshutdown.exe 并失败。您有一些解决方案:

    • 使用 Sysnative 来访问真正的 System32 文件夹:system(R"(C:\Windows\Sysnative\psshutdown -d -t 0)");
    • Turn off file system redirection 明确(一般应避免)
    • 或者更好地将您的应用程序重新编译为 64 位应用程序

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多