本文实例讲述了Python实现查看系统启动项功能。分享给大家供大家参考,具体如下:
一、代码
# -*- coding:utf-8 -*- #! python3 from win32api import * from win32con import * def GetValues(fullname): name =str.split(fullname,'\\',1) try: if name[0] == 'HKEY_LOCAL_MACHINE': key = RegOpenKey(HKEY_LOCAL_MACHINE,name[1],0,KEY_READ) elif name[0] == 'HKEY_CURRENT_USER': key = RegOpenKey(HKEY_CURRENT_USER,name[1],0,KEY_READ) elif name[0] == 'HKEY_CLASSES_ROOT': key = RegOpenKey(HKEY_CLASSES_ROOT,name[1],0,KEY_READ) elif name[0] == 'HKEY_CURRENT_CONFIG': key = RegOpenKey(HKEY_CURRENT_CONFIG,name[1],0,KEY_READ) elif name[0] == 'HKEY_USERS': key = RegOpenKey(HKEY_CURRENT_CONFIG,name[1],0,KEY_READ) else: print("err,no key named %s" % name[0]) info = RegQueryInfoKey(key) for i in range(0,info[1]): ValueName = RegEnumValue(key,i) print(str.ljust(ValueName[0],30),ValueName[1]) RegCloseKey(key) except: pass if __name__ == '__main__': keyNames =['HKEY_LOCAL_MACHINE\\SOFTWARE\\\Microsoft\\\Windows\\\CurrentVersion\\\Run',\ 'HKEY_LOCAL_MACHINE\\SOFTWARE\\\Microsoft\\\Windows\\\CurrentVersion\\\RunOnce',\ 'HKEY_LOCAL_MACHINE\\SOFTWARE\\\Microsoft\\\Windows\\\CurrentVersion\\\RunOnceEx',\ 'HKEY_CURRENT_USER\\SOFTWARE\\\Microsoft\\\Windows\\\CurrentVersion\\\RunOnce',\ 'HKEY_CURRENT_USER\\SOFTWARE\\\Microsoft\\\Windows\\\CurrentVersion\\\Run'] for keyName in keyNames: print('\n') print(keyName) GetValues(keyName)
二、运行结果:
HKEY_LOCAL_MACHINE\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run
360Safetray "D:\Program Files\360\360Safe\safemon\360tray.exe" /start
ApacheTomcatMonitor "C:\Tomcat 6.0\bin\tomcat6w.exe" //MS//Tomcat6
HKEY_LOCAL_MACHINE\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce
HKEY_LOCAL_MACHINE\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnceEx
HKEY_CURRENT_USER\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce
HKEY_CURRENT_USER\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run
360sd "D:\Program Files\360\360sd\360sdrun.exe"
ctfmon "C:\Windows\system32\ctfmon.exe"
sesvc "C:\Users\Administrator\AppData\Roaming\360se6\Application\components\sesvc\sesvc.exe" /b:1 /c:1
QQ2009 "D:\Program Files\Tencent\QQ\Bin\QQ.exe" /background
注:此处涉及注册表操作,需要有系统管理员权限
希望本文所述对大家Python程序设计有所帮助。
Python实现查看系统启动项功能示例
- Author -
chengqiuming声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@