Advertisement
Python253

fast_shutdown

Mar 18th, 2024
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. fast_shutdown.py
  5.  
  6. This script modifies the shutdown timeout value in the Windows registry.
  7.  
  8. It sets the value of 'WaitToKillServiceTimeout' under the registry key
  9. 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control' to 500 milliseconds,
  10. allowing for a faster shutdown process.
  11.  
  12. This modification can potentially reduce the time it takes for Windows to
  13. shut down after initiating the shutdown command.
  14.  
  15. Note: Running this script requires administrative privileges.
  16. """
  17.  
  18. import winreg as reg
  19.  
  20. def modify_shutdown_timeout():
  21.     """
  22.    Modify the shutdown timeout value in the Windows registry.
  23.  
  24.    This function attempts to open the registry key for modification and sets
  25.    the 'WaitToKillServiceTimeout' value to 500 milliseconds. If successful,
  26.    it prints a success message; otherwise, it prints an error message.
  27.  
  28.    Returns:
  29.        None
  30.    """
  31.     try:
  32.         # Open the key for modification
  33.         key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Control', 0, reg.KEY_SET_VALUE)
  34.         # Set the value of WaitToKillServiceTimeout to 500 (500 milliseconds)
  35.         reg.SetValueEx(key, 'WaitToKillServiceTimeout', 0, reg.REG_SZ, '500')
  36.         # Close the key
  37.         reg.CloseKey(key)
  38.         print("Shutdown timeout modified successfully.")
  39.     except Exception as e:
  40.         print(f"Error occurred while modifying shutdown timeout: {e}")
  41.  
  42. def main():
  43.     """
  44.    Main function to execute the script.
  45.  
  46.    Returns:
  47.        None
  48.    """
  49.     modify_shutdown_timeout()
  50.  
  51. if __name__ == "__main__":
  52.     main()
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement