Sunday 9 February 2014

C program to shutdown restart logoff hibernate computer in windowsxp windows7 and ubuntu

C program To Shutdown Computer in Windows xp

This is a program to Shutdown your computer by using C programming language code. This code will first ask you for the confirmation whether youwant to shutdown the computer or not. Depending on confirmation passed by user This program shutdown the computer or exit from executionif user don't want to shutdown computer. Firstly it will asks you
 to shutdown your computer if you press 'y' the  your computer will shutdown in 30 seconds, 


Logic Behind This program


In this program we have used library file that invoked or calls function of  "stdlib.h". This function in stdlib.h lubrary is used to  run an exe file "shutdown.exe" which is availiable in directory path
"C:\WINDOWS\system32"

Windows XP provides numerous options to use or parameters to pass to shutdown.exe 
while executing shutdown.exe 

For Example
  -s option shutdown the computer after 30 seconds

  -t :- This option allows you to specify the time along with shutdown command to specify after how much time computer will be shutdown If you want to shutdown your computre immediately then you canuse  "shutdown -s -t 0"

  Where -s parameter is stands for shutdown it denotes or pass parameter to shutdown.exe file to denotes shutdown.exe that user wants to shutdown this computer

"-t 0"  this denotes we are specifying time so that after that time computer must be shutdown. you can also specify time you want

-r This paramter is used to restart your computer


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

main()
{
   char ch;

   printf("Do you want to shutdown your computer now )\n");
   printf("Press Y for Yes\n");
   printf("Press N for No\n");
   scanf("%c",&ch);

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

   return 0;
}


C program To Shutdown Computer in Windows 7

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

main()
{
   char ch;

   printf("Do you want to shutdown your computer now \n");
   printf("Press Y for Yes\n");
   printf("Press N for No\n");
   scanf("%c",&ch);

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

   return 0;
}


C program To Shutdown Computer in Ubuntu


To Run this program in Ubuntu you must be logged in as root user
#include <stdio.h>

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



C Program To Shutdown Restart Logoff and Hibernate Program


The below availibale program can be used to shutdown your computer , to restart, logoff and hibernate you computer using c programming language

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

void main()
{
int ch;
clrscr();
printf("\n\n------------SHUTDOWN MENU----------------\n");
printf("Press1 For Shutdownn\nPress2 For Restart\n Press3  For Logoff\n Press4  for Hibernate\n5.exit”");
printf("\nEnter Your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:system("shutdown -s");
break;
case 2:system("shutdown -r");
break;
case 3:system("shutdown -l");
break;
case 4:system("shutdown -h");
break;
case 5:exit(1);
break;
default:printf("Invalid choice");
}
getch();
}

Happy Coding 

Don't Forget To Share This Post on Social Networks like Facebook , Twitter. Share your questions and how you like this post

Share this

2 Responses to "C program to shutdown restart logoff hibernate computer in windowsxp windows7 and ubuntu"