如下所示:
#!/usr/bin/python#-*-coding:utf-8-*-import _winreg as wr #导入内置的windows注册表操作库import osfrom socket import *import getpassdef GetStart(): key = r'SOFTWARE/Microsoft/Windows/CurrentVersion/Run' aRegL = wr.ConnectRegistry(None,wr.HKEY_LOCAL_MACHINE) aRegC = wr.ConnectRegistry(None,wr.HKEY_CURRENT_USER)#getpass.getuser()为得到当前的用户名 startdir = os.listdir(r'C:/Users'+ os.sep + getpass.getuser() + r'/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup') startExe = {'localmachine':[],'currentuser':[]} startExe['startdir'] = startdir try: aKeyL = wr.OpenKey(aRegL,key)#打开键,返回句柄 aKeyC = wr.OpenKey(aRegC,key) for i in range(1024): try: startExe['localmachine'].append( wr.EnumValue(aKeyL,i)) except: break #异常就是终点,退出循环 for i in range(1024): try: startExe['currentuser'].append( wr.EnumValue(aKeyC,i)) except: break finally: wr.CloseKey(aKeyL) wr.CloseKey(aKeyC) return startExedef main(): import sys reload(sys) sys.setdefaultencoding( "utf-8" ) start = GetStart() #这个函数返回一个字典 print 'LocalMachine'.center(50,'*') for i in start['localmachine']:#迭代字典中的数据 print i print 'CurrentUser'.center(50,'*') for i in start['currentuser']: print i print 'StartUp dir'.center(50,'*') for i in start['startdir']: print iif __name__== "__main__": main()
以上这篇python得到windows自启动列表的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林站长站。
新闻热点
疑难解答