C++ Shutdown Using C++ Code

C++ Shutdown Using C++ Code

How to Shutdown a Computer using C++ Code

Shutdown & Restart Computer in C++

  • To shutdown and restart you computer using C++ programming, just call the function system() of stdlib.h library which will call the cmd or terminal.
  • So to shutdown and restart your computer, just place your code (including full path) to shutdown and restart your computer.
  • Following C++ program made for both i.e., to shutdown your computer or to restart your computer (shutdown or turn off then turn on), first it will ask to the user that either he/she want to shutdown computer or want to restart computer. 
  • Option 1 is given for shutdown computer and option 2 is given for restart computer. 
  • When the option is entered, then widows system file will be executed which is placed inside the function system() of stdlib.h that letting the system to either shutdown computer or restart your computer. 
  • The delay to shutdown computer or restart computer is 20 second. This time is taken by the system to shutdown computer or restart computer.
  •  But you can change this time like you can make time 0 to shutdown computer or restart computer immediately or you can increase the time to make shutdown computer or restart computer after the given time.


using namespace std;
int main()
int choice;
cout<<"1. Shutdown Your Computer \n";
cout<<"2. Restart Your Computer \n";
cout<<"\n Enter your choice : ";
case 1 : cout<<"Your system will be shutdown after 20 seconds \n";
"c:\\windows\\system32\\shutdown /s /t 20 \n\n");
case 2 : cout<<"Your system will be restarted in 20 seconds\n";
"c:\\windows\\system32\\shutdown /r /t 20\n\n");
default : cout<<"Wrong Choice..!!\n";
return 0;

  • shutdown /s -- The shutdown command. This shuts down the computer when you run it.
  • shutdown /r -- Shuts down the computer, and restarts it afterwards.
  • /t 20 -- Sets the timeout period before the shutdown. The default is 30 seconds, and you may speed things up by setting /t 20.

More Articles of Shaik Ismail:

Name Views Likes
C++ Shutdown Using C++ Code 385 1
C++ Majority Element (LeetCode) 328 0
C++ Missing Number(LeetCode) 155 0
C++ Count set bits in an integer 551 0
C++ Power of Two Leetcode BitManipulation 446 0
C++ Single Number LeetCode Bit Manipulation 214 0
C++ Radix Sort 186 0
C++ Wave Sort 161 0
C++ Counting Sort 155 0
C++ DNF Algorithm for Sorting 0,1,2 320 0
C++ Merge Sort 157 0
C++ Quick Sort 232 0
C++ Insertion Sort 153 0
C++ Selection Sort 167 0
C++ Bubble Sort 204 0
C++ DFS for a Graph 182 0
C++ BFS in Graph 197 0
C++ Graph Representation (Adjacency list) 160 0
C++ Graph Representation 181 0
C++ Basics of Graph Data Structure 162 0
C++ Diameter of a Binary Tree 193 0
C++ Check if a binary tree is a BST or not 493 0
C++ Heap Sort 364 0
C++ Deletion in Heaps 380 0
C++ Insertion of Elements in Heap 157 0
C++ Basics of Heap Data Structure 152 0
C++ Deletion in AVL Trees 138 0
C++ AVL Rotations 238 0
C++ AVL Tree 144 0
C++ Deletion of Nodes in BST 494 0
C++ Kth Largest Element in BST 149 0
C++ Kth Smallest Element in BST 175 0
C++ Searching in BST 137 0
C++ Insertion of Nodes in BST 138 0
C++ Basics of BST Part - 1 337 0
C++ Binary Tree is a SumTree or Not 122 0
C++ Sum of all leaf nodes 126 0
C++ Identical Binary Trees 132 0
C++ Mirror Binary Tree 190 0
CPP Project or program to get six subjects marks of a student and then calculate its total, average and percentage and display them on the screen 145 0
C++ Lowest Common Ancestor 143 0
C++ Bottom View of a Binary Tree 183 0
C++ Top View of a Binary Tree 131 0
C++ Vertical Order Traversal of a Binary Tree 198 0
C++ Level Order Traversal of a Binary Tree 172 0
C++ Height of the Binary Tree (Code) 131 0
C++ Binary Tree Representation and Traversals (Code) 169 1
C++ Binary Tree 135 0
C++ Basics of Tree Data Structure PART - 2 147 0
Tree 133 1
Basics of Tree Data Structure PART - 1 98 0