Advertisement
Python253

execute_shutdown

Mar 18th, 2024
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.58 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # Filename: execute_shutdown.py
  3. # Version: 1.00
  4. # Author: Jeoi Reqi
  5.  
  6. """
  7. EXECUTE SHUTDOWN:
  8.  
  9. Purpose:
  10.    This script automates the creation of a shortcut named 'SHUTDOWN' on the user's desktop.
  11.    When activated, this shortcut initiates an immediate system shutdown.
  12.  
  13. Functionality:
  14.    The shortcut is configured to execute the shutdown command with specific arguments: '-s -t 0 -f'.
  15.    These arguments direct the system to commence an instantaneous shutdown, forcibly closing any active applications without user intervention.
  16.  
  17. Additional Configuration:
  18.    In addition to configuring the shutdown command, the script sets the working directory of the shortcut to 'C:\WINDOWS\system32'.
  19.    This ensures that the shutdown command executes from the appropriate location within the system environment.
  20.  
  21. Requirements:
  22.    - Python 3
  23.    - Windows OS (Supported Versions: Vista - 11)
  24.  
  25. Notes:
  26.    - Administrative privileges are required to run this script successfully.
  27.    - As a precautionary measure, it is advisable to create a backup of the registry before executing any modifications.
  28. """
  29.  
  30. import os
  31. import winshell
  32.  
  33. def create_shutdown_shortcut():
  34.     """
  35.    Create a shortcut on the desktop named 'SHUTDOWN' that executes the shutdown command.
  36.  
  37.    This function creates a shortcut on the user's desktop that, when clicked, initiates a system shutdown.
  38.  
  39.    Returns:
  40.        None
  41.    """
  42.     # Path to the desktop folder
  43.     desktop_folder = winshell.desktop()
  44.  
  45.     # Path to the shortcut
  46.     shortcut_path = os.path.join(desktop_folder, "SHUTDOWN.lnk")
  47.  
  48.     # Full path to shutdown.exe
  49.     shutdown_path = os.path.join(os.environ["SystemRoot"], "system32", "shutdown.exe")
  50.  
  51.     try:
  52.         # Create the shortcut
  53.         with winshell.shortcut(shortcut_path) as shortcut:
  54.             shortcut.path = shutdown_path
  55.             shortcut.arguments = "-s -t 0 -f"
  56.             shortcut.description = "Shutdown"
  57.  
  58.             # Set custom icon for the shortcut
  59.             icon_path = os.path.join(os.environ["SystemRoot"], "system32", "shell32.dll")
  60.             shortcut.icon_location = (icon_path, 27)  # Index of the red power button icon
  61.            
  62.             # Set the "Start in" property
  63.             shortcut.working_directory = os.path.join(os.environ["SystemRoot"], "system32")
  64.  
  65.             shortcut.write()
  66.         print("Shortcut 'SHUTDOWN' created successfully on the desktop.")
  67.     except Exception as e:
  68.         print(f"Error occurred while creating shortcut: {e}")
  69.  
  70. if __name__ == "__main__":
  71.     create_shutdown_shortcut()
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement