Advertisement
Python253

fast_shutdown_mod

Mar 18th, 2024
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: fast_shutdown_mod.py
  4. # Version: 1.00
  5. # Author: Jeoi Reqi
  6.  
  7. r"""
  8. This script modifies the shutdown timeout value in the Windows registry.
  9.  
  10. It sets the value of 'WaitToKillServiceTimeout' under the registry key 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control' to user specified value between 500 & 5,000 milliseconds,
  11. allowing for a faster shutdown process.
  12.  
  13. This modification can potentially reduce the time it takes for Windows to
  14. shut down after initiating the shutdown command.
  15.  
  16. Note: Running this script requires administrative privileges.
  17. """
  18.  
  19. import winreg as reg
  20.  
  21. def modify_shutdown_timeout(timeout):
  22.     """
  23.    Modify the shutdown timeout value in the Windows registry.
  24.  
  25.    This function attempts to open the registry key for modification and sets
  26.    the 'WaitToKillServiceTimeout' value to the specified timeout value.
  27.    If successful, it prints a success message; otherwise, it prints an error message.
  28.  
  29.    Args:
  30.        timeout (int): The timeout value in milliseconds.
  31.  
  32.    Returns:
  33.        None
  34.    """
  35.     try:
  36.         # Open the key for modification
  37.         key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Control', 0, reg.KEY_SET_VALUE)
  38.         # Set the value of WaitToKillServiceTimeout to the specified timeout
  39.         reg.SetValueEx(key, 'WaitToKillServiceTimeout', 0, reg.REG_SZ, str(timeout))
  40.         # Close the key
  41.         reg.CloseKey(key)
  42.         print("Shutdown timeout modified successfully.")
  43.     except Exception as e:
  44.         print(f"Error occurred while modifying shutdown timeout: {e}")
  45.  
  46. def main():
  47.     """
  48.    Main function to execute the script.
  49.  
  50.    Prompts the user for input to specify the timeout value,
  51.    then calls the modify_shutdown_timeout function with the specified value.
  52.  
  53.    Returns:
  54.        None
  55.    """
  56.     try:
  57.         timeout = int(input("Enter the timeout value (between 500 and 5000 milliseconds): "))
  58.         if 500 <= timeout <= 5000:
  59.             modify_shutdown_timeout(timeout)
  60.         else:
  61.             print("Invalid timeout value. Please enter a number between 500 and 5000.")
  62.     except ValueError:
  63.         print("Invalid input. Please enter a valid number.")
  64.  
  65. if __name__ == "__main__":
  66.     main()
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement