首页 > 编程 > Python > 正文

Python实现查看系统启动项功能示例

2020-01-04 15:07:54
字体:
来源:转载
供稿:网友

本文实例讲述了Python实现查看系统启动项功能。分享给大家供大家参考,具体如下:

一、代码

# -*- coding:utf-8 -*-#! python3from 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:    passif __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教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表