win7下python禁止开机自启动
2014-10-18 19:27
274 查看
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 Thunder BaofengPlatform
然后python读取配置文件,删除对应的注册表项,代码如下:
</pre><pre name="code" class="python">#filename:disableAutoRun.py #disable all things that auto run at the windows startup. import win32api import 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
相关文章推荐
- C#开发的软件如何不让360禁止开机自动启动
- WIN7下怎么去掉安装时的硬盘引导开机启动选项
- win7开机自启动虚拟路由器(续)
- win7设置让应用程序默认以管理员开机启动
- win7设置让应用程序默认以管理员开机启动
- 解决Win7开机时至正在启动死机故障
- windows环境下配置python脚本的开机启动
- 开机启动win7,自动启动突出显示的选择之前的秒数有30秒
- win7 开机自动启动不好使
- 提高开机启动速度 win7开机启动项优化设置技巧
- WIN7开机启动项目
- Win7下设置everything开机自动启动
- 禁止360开机自动启动
- win7开机自启动虚拟路由器的方法
- window基础-1:win7开机按ctrl+alt+delete启动
- (DIY)修改win7 开机 “正在启动 windows”
- Win7如何提升为管理员权限,如何开机启动需要管理员权限的程序,解决win7开机不能自动运行的问题等
- Ubuntu 10.04 禁止mysql服务开机启动
- Win7如何提升为管理员权限,如何开机启动需要管理员权限的程序,解决win7开机不能自动运行的问题等
- 如何设置让 Everything 在 Win7 下开机启动 - 小众软件