Advertisement
Python253

clipboard_fix_csv_reset

May 31st, 2024
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.82 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: clipboard_fix_csv_reset.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    - This script is designed to fix issues related to clipboard functionality on Windows systems by resetting and restarting essential services.
  10.    - Specifically, it targets the "Remote Desktop Services UserMode Port Redirector" and "ClipSVC" services, which are critical for clipboard operations.
  11.  
  12.    - The script first stops these services using the 'net stop' command, ensuring that any existing processes associated with them are terminated gracefully.
  13.    - It then starts the services again using the 'net start' command, effectively resetting them to their default state.
  14.  
  15.    - By executing this script, users can resolve common clipboard problems on Windows, such as malfunctioning clipboard operations or locked memory issues.
  16.    - This script provides a convenient and efficient way to address these issues without the need for manual intervention or complex troubleshooting steps.
  17.  
  18. Requirements:
  19.    - Python 3.x
  20.    - Administrative privileges may be required for execution.
  21.    
  22. Usage:
  23.    - Run the script with Python 3.x from the command line.
  24.    - Ensure administrative privileges are granted if prompted.
  25.  
  26. Example Output:
  27.  
  28.            [CLIPBOARD FIX CSV RESET]
  29.  
  30.  
  31.    Clearing clipboard...
  32.  
  33.    Stopping service:
  34.    Remote Desktop Services UserMode Port Redirector
  35.    The Remote Desktop Services UserMode Port Redirector service is stopping.
  36.    The Remote Desktop Services UserMode Port Redirector service was stopped successfully.
  37.  
  38.  
  39.    Starting service:
  40.    Remote Desktop Services UserMode Port Redirector
  41.    The Remote Desktop Services UserMode Port Redirector service is starting.
  42.    The Remote Desktop Services UserMode Port Redirector service was started successfully.
  43.  
  44.  
  45.    Stopping service:
  46.    ClipSVC
  47.    The Client License Service (ClipSVC) service is stopping.
  48.    The Client License Service (ClipSVC) service was stopped successfully.
  49.  
  50.  
  51.    Starting service:
  52.    ClipSVC
  53.    The Client License Service (ClipSVC) service is starting.
  54.    The Client License Service (ClipSVC) service was started successfully.
  55.  
  56.  
  57.            - All Processes Have Completed.
  58.            - Clipboard Data Has Been Cleared.
  59.            - Services Have All Been Reset.
  60.  
  61.               Ending Program... GoodBye!
  62.              
  63. Additional Notes:
  64.    - Ensure 'net stop' and 'net start' commands are available.
  65.    - Verify service status post-execution for confirmation.
  66. """
  67.  
  68. import subprocess
  69. import ctypes
  70.  
  71. def disable_clipboard():
  72.     """
  73.    Clears the current content of the clipboard.
  74.    """
  75.     ctypes.windll.user32.OpenClipboard(0)
  76.     ctypes.windll.user32.EmptyClipboard()
  77.     ctypes.windll.user32.CloseClipboard()
  78.  
  79. def stop_service(service_name):
  80.     """Stop the specified Windows service."""
  81.     subprocess.run(["net", "stop", service_name], shell=True)
  82.  
  83. def start_service(service_name):
  84.     """Start the specified Windows service."""
  85.     subprocess.run(["net", "start", service_name], shell=True)
  86.  
  87. def main():
  88.     """Main function to stop and start essential services."""
  89.     services = [
  90.         "Remote Desktop Services UserMode Port Redirector",
  91.         "ClipSVC"
  92.     ]
  93.     print("\n\t\t[CLIPBOARD FIX CSV RESET]\n\n")
  94.    
  95.     # Clear clipboard before stopping services
  96.     print("Clearing clipboard...")
  97.     disable_clipboard()
  98.    
  99.     for service in services:
  100.         print(f"\nStopping service:\n{service}")
  101.         stop_service(service)
  102.         print(f"\nStarting service:\n{service}")
  103.         start_service(service)
  104.     print("\n\t\t- All Processes Have Completed.\n\t\t- Clipboard Data Has Been Cleared.\n\t\t- Services Have All Been Reset.\n\n\t\t   Ending Program... GoodBye!\n")
  105.  
  106. if __name__ == "__main__":
  107.     main()
  108.  
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement