In this example, We will write a program using C++ to shutdown and restart computer. We will use the system function which is in stdlib.h header file.
For the program to shutdown and restart computer, We will use the following commands that we will use the system function which is in stdlib.h header file.
shutdown /s /t timeout_in_seconds
To restart a computer, You can use following commands
shutdown /r /t timeout_in_seconds
You can check the cmd commands for more details. When you execute the following commands then, You will see the popup as below image
Lets look and example to make clear concepts
using namespace std;
cout << "Choose one of the option from menu: \n";
cout << "1. Shutdown Your Computer \n";
cout << "2. Restart Your Computer \n";
cout << "3. Exit\n";
cout << "\n Enter your choice : ";
cin >> choice;
cout << "System will shutdown after 30 seconds \n";
system("C:\\windows\\system32\\shutdown /s /t 30 \n\n");
cout << "System will restart in 30 seconds\n";
system("C:\\windows\\system32\\shutdown /r /t 30\n\n");
cout << "Wrong Choice!!\n";
When you run this program then,
Choose one of the option from menu:
1. Shutdown Your Computer
2. Restart Your Computer
First you will see above output then you have to enter of the option.
Get the latest tutorials, examples and projects updates.
We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.
Disable Ad Block
Want Same System