Facebook
From dope/donp, 1 Year ago, written in C++.
Embed
Download Paste or View Raw
Hits: 161
  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. int main()
  5. {
  6.     std::cout << "Enter '1' to shut down or '2' to restart your computer: ";
  7.     int choice;
  8.     std::cin >> choice;
  9.  
  10.     switch (choice)
  11.     {
  12.         case 1:
  13.             // Shut down the computer
  14.             std::cout << "Shutting down your computer..." << std::endl;
  15.             Sleep(1000); // Sleep for 1 second to give the user a chance to see the message
  16.             ExitWindowsEx(EWX_SHUTDOWN, 0);
  17.             break;
  18.  
  19.         case 2:
  20.             // Restart the computer
  21.             std::cout << "Restarting your computer..." << std::endl;
  22.             Sleep(1000); // Sleep for 1 second to give the user a chance to see the message
  23.             ExitWindowsEx(EWX_REBOOT, 0);
  24.             break;
  25.  
  26.         default:
  27.             // Invalid input
  28.             std::cout << "Invalid choice. Please try again." << std::endl;
  29.             break;
  30.     }
  31.  
  32.     return 0;
  33. }
  34.