1

Here is my program to shutdown the PC in c++, and I use vs code editor and WSL to run this program:

          #include<iostream>
          #include<stdlib.h>
          int main()
          {

             system("C:\\Windows\\System32\\shutdown /i ");

          }

I got this message sh: 1: C:WindowsSystem32shutdown: not found.

1 Answers1

3

Make sure you use the appropriate path. The correct form for WSL via Linux is "/mnt/c/Windows/System32/shutdown.exe" as mentioned by prog-fh and code_fodder.

So this will work: (I haven't tested it in WSL, but the above users did and know better)

std::system("/mnt/c/Windows/System32/shutdown.exe /i");

or for shutdown you can use s as well:

std::system("/mnt/c/Windows/System32/shutdown.exe /s"); 

Likewise, for restarting, use r:

std::system("/mnt/c/Windows/System32/shutdown.exe /r");
  • ummm... this can't work. Are you sure you are using WSL (i.e Linux)? - You're anwer will result in the exact same error... You need to use linux commands - as mentioned in the comment section by prog-fh – code_fodder Apr 13 '20 at 15:25
  • @code_fodder Am not using WSL. I tested this on Windows via VSC. I realize WSL is a bit tricky since although it has support for windows with Linux binaries, it would work like how a virtual box works on a windows native system. (considering the reverse) But then again, the only thing what could be possibly wrong is the path (which I mentioned in my answer). The commands apply the same for windows. –  Apr 13 '20 at 15:40
  • The OP *is* using WSL so if you are not - that is not really relevant. Consider using the correct form for WSL (linux) that fixes the OPs actual question: "i got this message sh: 1: C:WindowsSystem32shutdown: not found". Which is to use `/mnt/c/Windows/System32/shutdown.exe ...`, where ... is whatever params. I tested this on WSL on Windows 10 - your answer gives the exact same error. – code_fodder Apr 13 '20 at 17:15
  • @code_fodder Corrected, I wasn't aware of that - thanks! you can remove your downvote –  Apr 13 '20 at 17:27
  • 1
    Better : ) , switched to a +1 – code_fodder Apr 13 '20 at 17:30