C, C++ Windows, Linux – Shutdown Computer

email me

Windows

#include <stdio.h>
#include <stdlib.h>

int main()
{
system("c:\\windows\\system32\\shutdown /s");
return 0;
}

 

Linux

#include <stdio.h>
#include <stdlib.h>
 
int main()
{ 
   system("shutdown -P now");
   
   return 0;
}

 

Notes

Shutdown
system(“c:\\windows\\system32\\shutdown /s”);

Restart
system(“c:\\windows\\system32\\shutdown /r”);

Logoff
system(“c:\\windows\\system32\\shutdown /l”);