C program toward shutdown or turn off computer
C Program toward shutdown your computer: This program turn off i.e shutdown your computer system. Firstly it will asks you toward shutdown your computer if you press 'y' the your computer will shutdown in 30 seconds, system function regarding "stdlib.h" is used toward run an executable file shutdown.exe which is present in C:\WINDOWS\system32 in Windows XP. You can use various options while executing shutdown.exe beneficial to example -s option shutdown the computer after 30 seconds, if you wish toward shutdown immediately then you can write "shutdown -s -t 0" as an argument toward system function. If you wish toward restart your computer then you can write "shutdown -r".
If you are using Turbo C Compiler then execute your file from folder. Press F9 toward build your executable file from source program. When you run from within the compiler by pressing Ctrl+F9 it may not work.
C programming code beneficial to Windows XP#include
#include
main()
{
char ch;
printf("Do you want toward shutdown your computer now (y/n)\n");
scanf("%c",&ch);
if (ch == 'y' || ch == 'Y') system("C:\\WINDOWS\\System32\\shutdown -s");
return 0;
}
C programming code beneficial to Windows 7#include
#include
main()
{
char ch;
printf("Do you want toward shutdown your computer now (y/n)\n");
scanf("%c",&ch);
if (ch == 'y' || ch == '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 regarding /s.
C programming code beneficial to Ubuntu Linux#include
int main()
{
system("shutdown -P now");
return 0;
}
You need toward be logged in as root user beneficial to above program toward execute otherwise you will get the message shutdown: Need toward be root, now specifies that you want toward shutdown immediately. '-P' option specifies you want toward power off your machine. You can specify minutes as:
shutdown -P "number regarding minutes"
For more help or options type at terminal: man shutdown.
-->