SYSTEM
This function invokes the command processor to execute a command.
PROGRAM
//Program to perform system shutdown and restart in Windows OS
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int n;
char ch;
cout<<"\n****MENU****\n";
cout<<"\n1. SHUTDOWN";
cout<<"\n2. RESTART";
cout<<"\n3. EXIT";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>n;
switch(n)
{
case 1:
{
system("C:\\Windows\\System32\\Shutdown /s /t 60");
cout<<"\nSYSTEM WILL SHUT DOWN IN 1 MINUTE!";
cout<<"\n\nDO YOU WANT TO ABORT SHUTDOWN(Y/N)?";
cin>>ch;
if(ch=='y' || ch=='Y')
{
system("C:\\Windows\\System32\\Shutdown /a");
cout<<"\nSYSTEM SHUT DOWN IS ABORTED!";
}
break;
}
case 2:
{
cout<<"\nSYSTEM WILL RESTART IN 1 MINUTE!";
system("C:\\Windows\\System32\\Shutdown /r /t 60");
cout<<"\n\nDO YOU WANT TO ABORT RESTART(Y/N)?";
cin>>ch;
if(ch=='y' || ch=='Y')
{
system("C:\\Windows\\System32\\Shutdown /a");
cout<<"\nSYSTEM RESTART IS ABORTED!";
}
break;
}
case 3:
{
exit(0);
}
default:
{
cout<<"\nWRONG CHOICE!";
break;
}
}
return 0;
}
OUTPUT
This function invokes the command processor to execute a command.
PROGRAM
//Program to perform system shutdown and restart in Windows OS
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int n;
char ch;
cout<<"\n****MENU****\n";
cout<<"\n1. SHUTDOWN";
cout<<"\n2. RESTART";
cout<<"\n3. EXIT";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>n;
switch(n)
{
case 1:
{
system("C:\\Windows\\System32\\Shutdown /s /t 60");
cout<<"\nSYSTEM WILL SHUT DOWN IN 1 MINUTE!";
cout<<"\n\nDO YOU WANT TO ABORT SHUTDOWN(Y/N)?";
cin>>ch;
if(ch=='y' || ch=='Y')
{
system("C:\\Windows\\System32\\Shutdown /a");
cout<<"\nSYSTEM SHUT DOWN IS ABORTED!";
}
break;
}
case 2:
{
cout<<"\nSYSTEM WILL RESTART IN 1 MINUTE!";
system("C:\\Windows\\System32\\Shutdown /r /t 60");
cout<<"\n\nDO YOU WANT TO ABORT RESTART(Y/N)?";
cin>>ch;
if(ch=='y' || ch=='Y')
{
system("C:\\Windows\\System32\\Shutdown /a");
cout<<"\nSYSTEM RESTART IS ABORTED!";
}
break;
}
case 3:
{
exit(0);
}
default:
{
cout<<"\nWRONG CHOICE!";
break;
}
}
return 0;
}
OUTPUT