-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram_Uninstaller.py
More file actions
87 lines (78 loc) · 3.38 KB
/
Program_Uninstaller.py
File metadata and controls
87 lines (78 loc) · 3.38 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import subprocess
import winreg
import speech_recognition as sr
def list_installed_programs():
"""List all installed programs on the Windows system."""
programs = []
uninstall_key = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" # Windows registry key to uninstall software
try:
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, uninstall_key) as key:
for i in range(winreg.QueryInfoKey(key)[0]):
subkey_name = winreg.EnumKey(key, i)
with winreg.OpenKey(key, subkey_name) as subkey:
try:
display_name = winreg.QueryValueEx(subkey, "DisplayName")[0]
programs.append(display_name)
except FileNotFoundError:
continue
except Exception as e:
print(f"Error accessing registry: {e}")
return programs
def uninstall_program(program_name):
"""Uninstall the specified program using its uninstall string."""
uninstall_key = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
try:
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, uninstall_key) as key:
for i in range(winreg.QueryInfoKey(key)[0]):
subkey_name = winreg.EnumKey(key, i)
with winreg.OpenKey(key, subkey_name) as subkey:
try:
display_name = winreg.QueryValueEx(subkey, "DisplayName")[0]
if display_name == program_name:
uninstall_string = winreg.QueryValueEx(subkey, "UninstallString")[0]
subprocess.run(uninstall_string, shell=True)
print(f"Uninstall command executed for: {program_name}")
return
except FileNotFoundError:
continue
except Exception as e:
print(f"Error accessing registry: {e}")
def recognize_speech():
"""Recognize speech input from the user."""
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Which program would you like to uninstall? Please say the number:")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
try:
spoken_number = recognizer.recognize_google(audio)
print(f"You said: {spoken_number}")
return int(spoken_number)
except sr.UnknownValueError:
print("Sorry, I could not understand the audio.")
except sr.RequestError as e:
print(f"Could not request results from Google Speech Recognition service; {e}")
except ValueError:
print("Please say a valid number.")
return None
def main():
programs = list_installed_programs()
if not programs:
print("No programs found.")
return
print("Installed Programs:")
for idx, program in enumerate(programs, start=1):
print(f"{idx}. {program}")
# Ask for verbal input
choice = recognize_speech()
if choice is not None and 1 <= choice <= len(programs):
program_to_uninstall = programs[choice - 1]
confirm = input(f"Confirm uninstallation of '{program_to_uninstall}'? (y/n): ")
if confirm.lower() == 'y':
uninstall_program(program_to_uninstall)
else:
print("Uninstallation canceled.")
else:
print("Invalid choice.")
if __name__ == "__main__":
main()