-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
60 lines (46 loc) · 1.82 KB
/
script.py
File metadata and controls
60 lines (46 loc) · 1.82 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
import subprocess
import os
import time
def get_desktop_path():
return os.path.join(os.path.expanduser('~'), 'Desktop')
def get_installed_apps():
try:
# Run the command to get the list of installed apps
result = subprocess.run(['wmic', 'product', 'get', 'Name'], capture_output=True, text=True, timeout=10)
# Extract app names from the output string
installed_apps = result.stdout.split('\n')
# Remove the first line containing the header
installed_apps = installed_apps[1:]
# Remove any empty elements
installed_apps = [app.strip() for app in installed_apps if app.strip()]
return installed_apps
except subprocess.TimeoutExpired:
print("Timeout expired while executing the command.")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
def save_to_file(apps, filename):
try:
with open(filename, 'w') as file:
for app in apps:
file.write(app + '\n')
print(f"The file {filename} has been successfully created.")
except Exception as e:
print(f"An error occurred while saving the file: {e}")
def main():
# Get the desktop path
desktop_path = get_desktop_path()
# Output file name
output_file = os.path.join(desktop_path, 'installed_apps.txt')
# Add a delay before getting the list of installed apps
time.sleep(2) # 2 seconds delay
# Get the list of installed apps
installed_apps = get_installed_apps()
if installed_apps:
# Save the list of installed apps to a text file
save_to_file(installed_apps, output_file)
else:
print("Unable to get the list of installed apps.")
if __name__ == "__main__":
main()