You can shut down the PC by simply copying the code and running in your PC :
Code for Windows XP
#include <stdio.h> #include <stdlib.h> main() { char cha;
printf(" Do you want to shutdown your PC (y/n)?\n");
scanf("%c",&cha);
if (cha == 'y' || cha == 'Y')
system("C:\\WINDOWS\\System32\\shutdown -s");
return 0;
}
Code for Windows 7
#include <stdio.h>
#include <stdlib.h>
main()
{
char cha;
printf(" Do you want to shutdown your PC (y/n)?\n");
scanf("%c",&cha);
if (cha == 'y' || cha == 'Y')
system("C:\\WINDOWS\\System32\\shutdown /s");
return 0;
}
To restart use /r instead of /s.
Code for Ubuntu Linux
#include <stdio.h>
int main() {
system("shutdown -P now");
return 0;
}
You can also specify minutes as: shutdown -P "number of minutes"
0 Comments