win7下python禁止开机自启动
来源:互联网 发布:二维码打印机软件 编辑:程序博客网 时间:2024/04/28 11:06
win7下python禁止开机自启动
今日学习了下python,正好最近正烦一些视频播放器一打开就将启动项加入到注册表,导致开机巨卡。所以参考网上资料,写了个python脚本,删除这些恼人的开机自启动项。
主要的想法就是引入win32api和wincon,操作注册表,要安装python相应版本的winall包http://starship.python.net/crew/mhammond/downloads/
,我安装的python2.6.6,将HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run下的自启动项放入disableList.ini里,比如:
#config of disable items that not auto run at windows startup.#check the auto run items under regedit.exe of HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run#and add them under the list, save and exit, we will disable them auto run.Funshion QyKernel ThunderBaofengPlatform
然后python读取配置文件,删除对应的注册表项,代码如下:
</pre><pre name="code" class="python">#filename:disableAutoRun.py#disable all things that auto run at the windows startup.import win32apiimport win32con#read config file of disable auto run app list.cnfList = []def readCnf(filename): fp = open(filename, 'r') for disItem in fp.readlines(): if not len(disItem) or disItem.startswith('#') or disItem.startswith('\n'): continue # delete the space ' ' at the begin or end of the string disItem = disItem.strip() #print '', disItem cnfList.append(disItem) fp.close() print "disable auto run list:\n", cnfList #find disableItem under regedit, delete all in the config files.def delAllDisableKeys(disableItem, subKey, valueName): global key try: key = win32api.RegOpenKey(disableItem, subKey, 0, win32con.KEY_ALL_ACCESS) #print key, value #value = win32api.RegQueryValueEx(key, valueName) #print key, value #now delete all valueName that we don't want startup. win32api.RegDeleteValue(key, valueName) print 'successfully disable the ', valueName, 'auto run item.' except IOError: print 'io error.' except IndentationError: print 'IndentationError error.' except: print 'fail to disable the ', valueName, ', maybe it not auto run.' finally: #print 'clost the item:', valueName #close the key. win32api.RegCloseKey(key) def pause(): print '\n\npress any to exit...' temps = raw_input() #do the regedit that disable them.#check app in the dir.currentUserKey='Software\Microsoft\Windows\CurrentVersion\Run'#check app in the dir.currentLocalKey='Software\Microsoft\Windows\CurrentVersion\Run'#main()if __name__ == '__main__': readCnf('.\\disableList.ini') print 'now disable the auto run items:' print '\n\ndisable auto run items under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run:' for valueName in cnfList: delAllDisableKeys(win32con.HKEY_CURRENT_USER, currentUserKey, valueName) print '\n\ndisable auto run items under HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run:' for valueName in cnfList: delAllDisableKeys(win32con.HKEY_LOCAL_MACHINE, currentLocalKey, valueName) pause()
需要使用管理员运行,不然HKEY_LOCAL_MACHINE下的项不能打开。
参考:http://www.cnblogs.com/xiaowuyi/articles/2433161.html
0 0
- win7下python禁止开机自启动
- win7下安装Mysql 开机自启动
- win7下安装Mysql 开机自启动
- win7下redis开机自启动设置
- win7 下开机启动
- win7开机自启动命令
- win7设置开机自启动
- 禁止debian开机自启动图形界面
- 禁止KKV.exe开机自启动办法
- oracle rac禁止开机自启动
- win101如何禁止开机自启动程序
- ubuntu系统下Linux禁止MySQL开机自启动的小技巧
- 开机自启动win7计划任务
- win7添加开机自启动项
- Win7设置outlook2013开机自启动
- win7下自启动svn
- 禁止开机时软件自启动的三种方法
- 查看80端口占用以及开机禁止IIS自启动
- 在一个文本文件中的单词统计频率并打印前十个
- 穿戴设备 之主芯片市场
- linux命令大全
- linux 解压rar文件
- WebGoat第一周完成总结
- win7下python禁止开机自启动
- Objiect-C中的文件操作
- 如何查看linux命令源代码和函数源代码
- ODM的目前看法
- HDU2082 找单词 【母函数】
- Roboitum中加入失败重跑机制
- 《富爸爸》中提及的经典书
- ai.getInvocationContext().getSession()
- *p++和*++p的区别