Last active
August 17, 2023 11:39
-
-
Save fastfingertips/03be8bb99e279e2097df809bb8cfff68 to your computer and use it in GitHub Desktop.
This Python script lets you add or remove the Recycle Bin folder from the 'This PC' section on Windows by modifying the Windows Registry with the 'reg add' or 'reg delete' command. Use it with caution as changes to the Registry can have negative effects on the system.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import ctypes | |
from PyQt5.QtCore import Qt | |
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QPushButton | |
def is_admin(): | |
try: return ctypes.windll.shell32.IsUserAnAdmin() | |
except: return False | |
class MainWindow(QMainWindow): | |
def __init__(self): | |
super().__init__() | |
self.setWindowTitle("Add/Remove Recycle Bin to/from This PC") | |
self.setFixedSize(500, 200) | |
# Add description label | |
label = QLabel(self) | |
label.setText("This program allows you to add or remove the Recycle Bin folder to/from the 'This PC' section in Windows. When you click the 'Add' button, the program adds the corresponding key to the Windows Registry using the 'reg add' command. When you click the 'Remove' button, the program removes the key from the Registry using the 'reg delete' command. Please note that modifying the Registry can have negative effects on the system, so use this program with caution.") | |
label.setAlignment(Qt.AlignCenter) | |
label.setWordWrap(True) | |
label.setGeometry(50, 20, 400, 100) | |
# Add button | |
self.add_button = QPushButton("Add", self) | |
self.add_button.setGeometry(100, 120, 100, 50) | |
self.add_button.clicked.connect(self.add_recycle_bin) | |
# Remove button | |
self.remove_button = QPushButton("Remove", self) | |
self.remove_button.setGeometry(300, 120, 100, 50) | |
self.remove_button.clicked.connect(self.remove_recycle_bin) | |
# Call check_status function to control the status of buttons | |
self.check_status() | |
def add_recycle_bin(self): | |
os.system('reg add HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MyComputer\\NameSpace\\{645FF040-5081-101B-9F08-00AA002F954E}') | |
self.check_status() | |
def remove_recycle_bin(self): | |
os.system('reg delete HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MyComputer\\NameSpace\\{645FF040-5081-101B-9F08-00AA002F954E} /f') | |
self.check_status() | |
def check_status(self): | |
# Check if the key exists in the registry | |
key_exists = bool(os.system('reg query HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MyComputer\\NameSpace\\{645FF040-5081-101B-9F08-00AA002F954E} >nul 2>nul')) | |
# Update the status of buttons | |
self.add_button.setEnabled(key_exists) | |
self.remove_button.setEnabled(not key_exists) | |
if not is_admin(): | |
# If the user is not an admin, ask for elevated privileges and run the script again | |
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1) | |
else: | |
# If the user is an admin, create and show the main window | |
app = QApplication(sys.argv) | |
window = MainWindow() | |
window.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment