AbyssalSwamp  ActivaUser
» Guest:  Register | Login | 会员列表

RSS subscription to this AbyssalSwamp  

Previous thread Next thread
     
Title: python检测windows7系统已经安装的软件  
  This topic was added by com at 2025-1-12 16:22 移动 
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
python检测windows7系统已经安装的软件

在Python中,我们可以使用psutil库来获取有关系统的信息,包括已安装的软件。psutil是一个跨平台库,可以用来获取系统利用率和进程相关的信息。 以下是一个示例脚本,该脚本将列出在Windows 7系统上安装的所有软件:

import psutil # 获取所有正在运行的进程 processes = psutil.pids() # 遍历每个进程,获取其详细信息 for pid in processes: try: process = psutil.Process(pid) print(f"进程名称: {process.name()}") print(f"进程详细信息: {process.exe()}") except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): pass
请注意,上述代码将列出所有正在运行的进程,包括操作系统进程和其他用户进程。其中psutil.Process(pid).name()返回的是进程名称,而psutil.Process(pid).exe()返回的是进程的可执行文件路径。这可以用来判断该进程属于哪个软件。 然而,这并不是获取已安装软件的最佳方式。因为在Windows中,一个软件可能会在多个进程中运行,或者可能没有运行任何进程。此外,有些软件可能没有直接的可执行文件,例如浏览器插件或服务。因此,如果你需要更准确地获取已安装软件的信息,可能需要使用更复杂的方法,例如查询Windows注册表或使用第三方库。




CAFFZ.com
2023-12-15 16:56#1
View profile  Blog  Send a short message  Top
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline


import winreg import psutil def get_installed_software(): installed_software = [] key_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path) as key: for i in range(0, winreg.QueryInfoKey(key)[0]): skey_name = winreg.EnumKey(key, i) skey_path = f"{key_path}\\{skey_name}" with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, skey_path) as skey: try: display_name = winreg.QueryValueEx(skey, "DisplayName")[0] installed_software.append(display_name) except FileNotFoundError: pass return installed_software def get_running_processes(): running_processes = [] for proc in psutil.process_iter(): try: running_processes.append(proc.name()) except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): pass return running_processes # 获取已安装的软件列表 installed_software = get_installed_software() print("已安装的软件:") for software in installed_software: print(software) # 获取正在运行的程序列表 running_processes = get_running_processes() print("\n正在运行的程序:") for process in running_processes: print(process)
列出内存程序。


Image attachment: 微信图片_20231215170645.png (2023-12-15 17:07, 28.81 K)





CAFFZ.com
2023-12-15 17:07#2
View profile  Blog  Send a short message  Top
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline


import winreg import psutil import requests def get_installed_software(): installed_software = [] key_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path) as key: for i in range(0, winreg.QueryInfoKey(key)[0]): skey_name = winreg.EnumKey(key, i) skey_path = f"{key_path}\\{skey_name}" with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, skey_path) as skey: try: display_name = winreg.QueryValueEx(skey, "DisplayName")[0] installed_software.append(display_name) except FileNotFoundError: pass return installed_software def get_running_processes(): running_processes = [] for proc in psutil.process_iter(): try: running_processes.append(proc.name()) except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): pass return running_processes def post_data(url, data): headers = {'Content-Type': 'application/json'} response = requests.post(url, json=data, headers=headers) print(response.text) # 获取已安装的软件列表 installed_software = get_installed_software() # 获取正在运行的程序列表 running_processes = get_running_processes() # 将数据以JSON格式打包 data = { 'installed_software': installed_software, 'running_processes': running_processes } # 将数据POST到192.168.10.1/post.php post_data('http://192.168.10.1/post.php', data)




CAFFZ.com
2023-12-15 18:08#3
View profile  Blog  Send a short message  Top
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline


Image attachment: 微信图片_20231218153032.png (2023-12-18 15:31, 71.52 K)





CAFFZ.com
2023-12-18 15:31#4
View profile  Blog  Send a short message  Top
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
python获取windows7系统已经安装的office 2010的序列号与注册信息

import winreg def get_office_registration(): key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Office\14.0\Registration") try: value = winreg.QueryValueEx(key, "SerialNumber")[0] registered_to = winreg.QueryValueEx(key, "RegisteredTo")[0] return { "Serial Number": value, "Registered To": registered_to } except FileNotFoundError: return None finally: winreg.CloseKey(key) def main(): result = get_office_registration() if result: print("Office 2010序列号与注册信息:") for key, value in result.items(): print(f"{key}: {value}") else: print("未找到Office 2010的注册信息。") if __name__ == "__main__": main()




CAFFZ.com
2023-12-18 15:56#5
View profile  Blog  Send a short message  Top
     


  Printable version | Recommend to a friend | Subscribe to topic | Favorite topic  


 


All times are GMT+8, and the current time is 2026-1-12 11:02 Clear informations ->sessions/cookies - Contact Us - CAFFZ - ZAKE