本文实例讲述了Python实现查看系统启动项功能。分享给大家供大家参考,具体如下:
一、代码
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
|
# -*- 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程序设计有所帮助。
原文链接:https://blog.csdn.net/chengqiuming/article/details/78600960