C program to Shut Down the PC

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 shutdown immediately use "C:\\WINDOWS\\System32\\ shutdown /s /t 0". 
To restart use /r instead of /s.

Code for Ubuntu Linux 

#include <stdio.h>
int main() {
system("shutdown -P now");
return 0;
} 
 
You should be root to perform this.
You can also specify minutes as: shutdown -P "number of minutes"

Post a Comment

0 Comments