forked from DevPops-Inc/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetProgramsOnWin.py
More file actions
55 lines (36 loc) · 1.67 KB
/
Copy pathgetProgramsOnWin.py
File metadata and controls
55 lines (36 loc) · 1.67 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
#!/bin/python
# get programs on Windows
import colorama, os, sys, traceback
from colorama import Fore, Style
from datetime import datetime
colorama.init()
def checkOsForWindows():
print("Started checking operating system at", datetime.now().strftime("%m-%d-%Y %I:%M %p"))
if sys.platform == "win32":
print(Fore.GREEN + "Operating System:", end=""); sys.stdout.flush()
os.system('ver')
print(Style.RESET_ALL, end="")
print("Finished checking operating system at", datetime.now().strftime("%m-%d-%Y %I:%M %p"))
print("")
else:
raise Exception("Sorry but this script only runs on Windows.")
def getPrograms():
print("\nGet Programs on Windows.\n")
checkOsForWindows()
try:
startDateTime = datetime.now()
print("Started getting programs at", startDateTime.strftime("%m-%d-%Y %I:%M %p"))
getWinApps = 'Powershell "Get-ItemProperty HKLM:\\Software\\Wow6432Node\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Select-Object DisplayName | Format-Table -Autosize"'
if os.system(getWinApps) != 0:
raise Exception("Error occurred while getting programs.")
print(Fore.GREEN + "Successfully got programs." + Style.RESET_ALL)
finishedDateTime = datetime.now()
print("Finished getting programs at", finishedDateTime.strftime("%m-%d-%Y %I:%M %p"))
duration = finishedDateTime - startDateTime
print("Total execution time: {0} second(s)".format(duration.seconds))
print("")
except Exception:
print(Fore.RED + "Failed to get programs.")
traceback.print_exc()
exit("" + Style.RESET_ALL)
getPrograms()