-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.py
36 lines (28 loc) · 1.08 KB
/
uninstall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import ctypes
import sys
import winreg
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def run_as_admin():
ctypes.windll.shell32.ShellExecuteW(
None, "runas", sys.executable, " ".join(sys.argv), None, 1)
def remove_context_menu():
if not is_admin():
print("The script is not running with admin rights. Trying to get admin rights...")
run_as_admin()
else:
with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, 'Directory\\Background\\shell', 0, winreg.KEY_ALL_ACCESS) as key:
try:
winreg.DeleteKey(key, 'Organize Files\\command')
winreg.DeleteKey(key, 'Organize Files')
print("Successfully removed the context menu entry.")
except FileNotFoundError:
print("The context menu entry was not found.")
except PermissionError:
print(
"Failed to remove the context menu entry. Try running the script as an administrator.")
if __name__ == "__main__":
remove_context_menu()