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

本文实例讲述了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_MACHINESOFTWARE\Microsoft\Windows\CurrentVersion\Run

360Safetray                    "D:Program Files360360Safesafemon360tray.exe" /start

ApacheTomcatMonitor            "C:Tomcat 6.0bintomcat6w.exe" //MS//Tomcat6

HKEY_LOCAL_MACHINESOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce

HKEY_LOCAL_MACHINESOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx

HKEY_CURRENT_USERSOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce

HKEY_CURRENT_USERSOFTWARE\Microsoft\Windows\CurrentVersion\Run

360sd                          "D:Program Files360360sd360sdrun.exe"

ctfmon                         "C:Windowssystem32ctfmon.exe"

sesvc                          "C:UsersAdministratorAppDataRoaming360se6Applicationcomponentssesvcsesvc.exe" /b:1 /c:1

QQ2009                         "D:Program FilesTencentQQBinQQ.exe" /background

注:此处涉及注册表操作,需要有系统管理员权限

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python文件与目录操作技巧汇总》、《Python文本文件操作技巧汇总》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程

希望本文所述对大家Python程序设计有所帮助。

0.236499s