Pages - Menu

Saturday, 19 July 2014

Shutdown system using C.

You can shutdown your system using a c program.
Here is the code to shut down the system in c.

For window xp:

(After 30 seconds)

 If you are using turbo c then you can not do that from the compiler directly you should execute the file from folder.
#include <stdio.h>
#include <stdlib.h>

int main()
{
   char c;

   printf("Do you want to shutdown your system: (y/n)\n");
   scanf("%c",&c);

   if (ch == 'y' || ch == 'Y')
      system("C:\\WINDOWS\\System32\\shutdown -s");
   return 0;
}


(Immediately)

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

int main()
{
   char c;

   printf("Do you want to shutdown your system: (y/n)\n");
   scanf("%c",&c);

   if (ch == 'y' || ch == 'Y')
      system("C:\\WINDOWS\\System32\\shutdown -s -t0");
   return 0;
}


Restart your system


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

int main()
{
   char c;

   printf("Do you want to shutdown your system: (y/n)\n");
   scanf("%c",&c);

   if (ch == 'y' || ch == 'Y')
      system("C:\\WINDOWS\\System32\\shutdown -r");
   return 0;
}

For window 7:


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

int main()
{
   char ch;

   printf("Do you want to shutdown your system: (y/n)\n");
   scanf("%c",&ch);

   if (ch == 'y' || ch == 'Y')
      system("C:\\WINDOWS\\System32\\shutdown /s");

   return 0;
}

For Ubuntu Linux and other:


You must be logged in as a root. You can also specify minutes after which u want to shut down -p "minutes".
#include <stdio.h>

int main() {
  system("shutdown -P now");
  return 0;

No comments:

Post a Comment