Thursday, 31 May 2012

C code to shutdown your computer



C language code to shutdown your computer...


This post will show a simple example to create a small shutdown application in C Programming.
The snippet shows a simple code to create .exe by compiling it under TurboC/C++ compiler.
I shut down my system in the same way by double-clicking  on  the exe file generated by compiling this program under C language.

//
// -- CODE –
//

// ***********************************************************************
// www.techterabyte.com C example!!!
// -- start of code
// header files
#include<stdio.h>
#include<stdlib.h>
void main()
{
   char choice;
   // enter  yes/no
   printf("Shutdown your computer now(y/n)?");
   printf("\t Yes:y/n),\n");
   printf("\t No:n/n) \n");
   scanf("%c",&choice);
   if( choice == 'y' || choice == 'Y' ) {
      system("C:\\WINDOWS\\System32\\shutdown -s");
   }
  getch();
}
// www.techterabyte.com C example!!!
// --end of code
// ***********************************************************************

Just compile it by using any compiler and create exe file.
I am using  Turbo C/C++ compiler

Below screenshot shows the code:

C programming - techterabyte.com
C program code to shutdown system



The screenshot shows the output which can be seen after -> Ctrl + F9
Enter y or Y and press enter--
C programming - techterabyte.com
enter value

After successfully running the program, copy the exe file from:
  •    TC\BIN\SHUTDOWN.exe
  •    To any location on the computer(or desktop)
  •    Just double click, enter y or Y
  •    Successful shutdown… 



___________________________________________________________________
Please comment and forward to others if you like this.
Other posts with video tutorial yet to come.....

"I am sure that blogs really help people around the world.
Let us follow this simple thinking of sharing knowledge . . ."



No comments:

Post a Comment