簡體   English   中英

通過 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");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM