在 WSL 中通过 C++ 关闭和重启 PC
Shutting down and Restarting PC via C++ in WSL
这是我用 C++ 关闭 PC 的程序,我使用 VS 代码编辑器和 WSL 来 运行 这个程序:
#include<iostream>
#include<stdlib.h>
int main()
{
system("C:\Windows\System32\shutdown /i ");
}
我收到这条消息 sh: 1: C:WindowsSystem32shutdown: not found
。
确保使用正确的路径。如 prog-fh 和 code_fodder.
所述,通过 Linux 的 WSL 的正确形式是 "/mnt/c/Windows/System32/shutdown.exe"
所以这会起作用:(我还没有在 WSL 中测试过,但上面的用户做过并且知道得更多)
std::system("/mnt/c/Windows/System32/shutdown.exe /i");
或者对于关机,您也可以使用 s
:
std::system("/mnt/c/Windows/System32/shutdown.exe /s");
同样,要重新启动,请使用 r
:
std::system("/mnt/c/Windows/System32/shutdown.exe /r");
这是我用 C++ 关闭 PC 的程序,我使用 VS 代码编辑器和 WSL 来 运行 这个程序:
#include<iostream>
#include<stdlib.h>
int main()
{
system("C:\Windows\System32\shutdown /i ");
}
我收到这条消息 sh: 1: C:WindowsSystem32shutdown: not found
。
确保使用正确的路径。如 prog-fh 和 code_fodder.
所述,通过 Linux 的 WSL 的正确形式是"/mnt/c/Windows/System32/shutdown.exe"
所以这会起作用:(我还没有在 WSL 中测试过,但上面的用户做过并且知道得更多)
std::system("/mnt/c/Windows/System32/shutdown.exe /i");
或者对于关机,您也可以使用 s
:
std::system("/mnt/c/Windows/System32/shutdown.exe /s");
同样,要重新启动,请使用 r
:
std::system("/mnt/c/Windows/System32/shutdown.exe /r");