Я разрабатываю скрипт Python для перечисления всех установленных приложений в моей системе Windows 11. Я хотел бы повторить те же результаты, отображаемые в Настройках> Приложения> Установленные приложения . Необязательно, я хотел бы перечислить приложения, установленные не только для моего пользователя, но и во всей системе.
Surfing the Web, я нашел эти четыре команды: < /p>
cmd1 = "Get-WmiObject -Class Win32_Product | Select-Object Name, Version, Architecture | Sort-Object Name"
cmd2 = "Get-AppxPackage | Select-Object Name, Version, Architecture | Sort-Object Name"
path = f"HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*"
cmd3 = f"Get-ItemProperty -Path {path} | Select-Object DisplayName, DisplayVersion, Architecture | Sort-Object Name"
path = f"HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*"
cmd4 = f"Get-ItemProperty -Path {path} | Select-Object DisplayName, DisplayVersion, Architecture | Sort-Object Name"
< /code>
Я разрабатываю простой код, чтобы запустить эти четыре команды последовательно: < /p>
def list_installed_apps(cmd: str):
# Run the PowerShell command and capture output
result = subprocess.run(["powershell", "-Command", cmd], capture_output=True, text=True)
# Split the result into lines and filter out unwanted lines
installed_apps = result.stdout.splitlines()
return installed_apps
##############################
# CMD 1
##############################
cmd = "Get-WmiObject -Class Win32_Product | Select-Object Name, Version, Architecture | Sort-Object Name"
apps_1 = list_installed_apps(cmd)
# Find the index of the header line and column label boundaries
header_index = [i for i, app in enumerate(apps_1) if app.find("Version") != -1][0]
header = apps_1[header_index]
bound_1 = header.find("Version")
bound_2 = header.find("Architecture")
# Remove the header and any empty lines
apps_1 = [app.strip() for app in apps_1 if app.strip() and "Name" not in app]
apps_1 = apps_1[1:] #removes the line of -------
apps_1_ordered = [
{"name": app[:bound_1], "version": app[bound_1:bound_2], "architecture": app[bound_2:]}
for app in apps_1
]
##############################
# CMD 2
##############################
cmd = "Get-AppxPackage | Select-Object Name, Version, Architecture | Sort-Object Name"
apps_2 = list_installed_apps(cmd)
# Find the index of the header line and column label boundaries
header_index = [i for i, app in enumerate(apps_2) if app.find("Version") != -1][0]
header = apps_2[header_index]
bound_1 = header.find("Version")
bound_2 = header.find("Architecture")
# Remove the header and any empty lines
apps_2 = [app.strip() for app in apps_2 if app.strip() and "Name" not in app]
apps_2 = apps_2[1:] #removes the line of -------
apps_2_ordered = [
{"name": app[:bound_1], "version": app[bound_1:bound_2], "architecture": app[bound_2:]}
for app in apps_2
]
##############################
# CMD 3
##############################
path = f"HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*"
cmd = f"Get-ItemProperty -Path {path} | Select-Object DisplayName, DisplayVersion, Architecture | Sort-Object Name"
apps_3 = list_installed_apps(cmd)
# Find the index of the header line and column label boundaries
header_index = [i for i, app in enumerate(apps_3) if app.find("DisplayVersion") != -1][0]
header = apps_3[header_index]
bound_1 = header.find("DisplayVersion")
bound_2 = header.find("Architecture")
# Remove the header and any empty lines
apps_3 = [app.strip() for app in apps_3 if app.strip() and "DisplayName" not in app]
apps_3 = apps_3[1:] #removes the line of -------
apps_3_ordered = [
{"name": app[:bound_1], "version": app[bound_1:bound_2], "architecture": app[bound_2:]}
for app in apps_3
]
##############################
# CMD 4
##############################
path = f"HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*"
cmd = f"Get-ItemProperty -Path {path} | Select-Object DisplayName, DisplayVersion, Architecture | Sort-Object Name"
apps_4 = list_installed_apps(cmd)
# Find the index of the header line and column label boundaries
header = apps_4[1]
bound_1 = header.find("DisplayVersion")
bound_2 = header.find("Architecture")
# Remove the header and any empty lines
apps_4 = [app.strip() for app in apps_4 if app.strip() and "DisplayName" not in app]
apps_4 = apps_4[1:] #removes the line of -------
apps_4_ordered = [
{"name": app[:bound_1], "version": app[bound_1:bound_2], "architecture": app[bound_2:]}
for app in apps_4
]
##############################
# SUM RESULTS OF ALL COMMANDS AND SAVE
##############################
all_apps = apps_1_ordered + apps_2_ordered + apps_3_ordered + apps_4_ordered
fileName = "" # SET YOUR NAME
with open(fileName, "w") as f:
for app in all_apps:
f.write(f"{app['name']} --- {app['version']} --- {app['architecture']}\n")
< /code>
К сожалению, этот содержимое файла не совсем соответствует приложениям, отсортированным в настройках. Как я могу получить этот список?
Подробнее здесь: https://stackoverflow.com/questions/794 ... python-scr
Как перечислить все приложения/программное обеспечение/программы, установленные на Windows 11 с помощью сценария Python ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Запустите программное обеспечение EXE с помощью приложения в Windows IIS
Anonymous » » в форуме Python - 0 Ответы
- 15 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Запустите программное обеспечение EXE с помощью приложения в Windows IIS
Anonymous » » в форуме Python - 0 Ответы
- 21 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Можно ли скомпилировать программное обеспечение ARM Windows C++ на хосте ARM Windows?
Anonymous » » в форуме C++ - 0 Ответы
- 70 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Можно ли скомпилировать программное обеспечение ARM Windows C++ на хосте ARM Windows?
Anonymous » » в форуме C++ - 0 Ответы
- 32 Просмотры
-
Последнее сообщение Anonymous
-