Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Filename: execute_shutdown.py
- # Version: 1.00
- # Author: Jeoi Reqi
- """
- EXECUTE SHUTDOWN:
- Purpose:
- This script automates the creation of a shortcut named 'SHUTDOWN' on the user's desktop.
- When activated, this shortcut initiates an immediate system shutdown.
- Functionality:
- The shortcut is configured to execute the shutdown command with specific arguments: '-s -t 0 -f'.
- These arguments direct the system to commence an instantaneous shutdown, forcibly closing any active applications without user intervention.
- Additional Configuration:
- In addition to configuring the shutdown command, the script sets the working directory of the shortcut to 'C:\WINDOWS\system32'.
- This ensures that the shutdown command executes from the appropriate location within the system environment.
- Requirements:
- - Python 3
- - Windows OS (Supported Versions: Vista - 11)
- Notes:
- - Administrative privileges are required to run this script successfully.
- - As a precautionary measure, it is advisable to create a backup of the registry before executing any modifications.
- """
- import os
- import winshell
- def create_shutdown_shortcut():
- """
- Create a shortcut on the desktop named 'SHUTDOWN' that executes the shutdown command.
- This function creates a shortcut on the user's desktop that, when clicked, initiates a system shutdown.
- Returns:
- None
- """
- # Path to the desktop folder
- desktop_folder = winshell.desktop()
- # Path to the shortcut
- shortcut_path = os.path.join(desktop_folder, "SHUTDOWN.lnk")
- # Full path to shutdown.exe
- shutdown_path = os.path.join(os.environ["SystemRoot"], "system32", "shutdown.exe")
- try:
- # Create the shortcut
- with winshell.shortcut(shortcut_path) as shortcut:
- shortcut.path = shutdown_path
- shortcut.arguments = "-s -t 0 -f"
- shortcut.description = "Shutdown"
- # Set custom icon for the shortcut
- icon_path = os.path.join(os.environ["SystemRoot"], "system32", "shell32.dll")
- shortcut.icon_location = (icon_path, 27) # Index of the red power button icon
- # Set the "Start in" property
- shortcut.working_directory = os.path.join(os.environ["SystemRoot"], "system32")
- shortcut.write()
- print("Shortcut 'SHUTDOWN' created successfully on the desktop.")
- except Exception as e:
- print(f"Error occurred while creating shortcut: {e}")
- if __name__ == "__main__":
- create_shutdown_shortcut()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement