给python解释器本身添加注册表
2017-03-02 22:48
344 查看
import sys from _winreg import * # tweak as necessary version = sys.version[:3] installpath = sys.prefix regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) installkey = "InstallPath" pythonkey = "PythonPath" pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( installpath, installpath, installpath ) def RegisterPy(): print "begin RegisterPy " try: print "open key : %s" % regpath reg = OpenKey(HKEY_CURRENT_USER, regpath) except EnvironmentError as e: try: reg = CreateKey(HKEY_CURRENT_USER, regpath) SetValue(reg, installkey, REG_SZ, installpath) SetValue(reg, pythonkey, REG_SZ, pythonpath) CloseKey(reg) except: print "*** EXCEPT: Unable to register!" return print "--- Python", version, "is now registered!" return if (QueryValue(reg, installkey) == installpath and QueryValue(reg, pythonkey) == pythonpath): CloseKey(reg) print "=== Python", version, "is already registered!" return CloseKey(reg) print "*** ERROR:Unable to register!" print "*** REASON:You probably have another Python installation!" def UnRegisterPy(): # print "begin UnRegisterPy " try: print "open HKEY_CURRENT_USER key=%s" % (regpath) reg = OpenKey(HKEY_CURRENT_USER, regpath) # reg = OpenKey(HKEY_LOCAL_MACHINE, regpath) except EnvironmentError: print "*** Python not registered?!" return try: DeleteKey(reg, installkey) DeleteKey(reg, pythonkey) DeleteKey(HKEY_LOCAL_MACHINE, regpath) except: print "*** Unable to un-register!" else: print "--- Python", version, "is no longer registered!" if __name__ == "__main__": RegisterPy()
相关文章推荐
- 将python2.7 添加进64位系统 的注册表
- PyCharm_汉化包_编译器字体和背景怎么设置?_怎么添加多个python解释器?
- 将python 添加进64位win7 的注册表
- 报错 no module named win32api 的解决方案 以及python添加注册表方法
- 在win环境下添加多个版本python解释器的方法
- Python Windows中将Python添加到注册表中
- 【Python】添加注册表信息脚本
- 脚本执行 把python添加到 注册表
- 将python2.7添加进64位系统的注册表方法
- Python 中添加中文注释以及中文输出解释器报错的解决办法
- 为python解释器添加tab补全
- mac PyCharm添加Python解释器及添加package路径的方法
- 修改注册表添加信任站点及启用Activex控件(转载)
- (Python编程)"添加Python,充分混和。"
- 注册表添加删除问题
- 菜鸟学Python(9):给文件添加内容,得到文件信息
- 由于Python本身自带的界面库功能并不强大,我们使用Python+wxPython作为界面开发平台,在公司新的项目中进行界面开发。开发过程使用Eclipse+PyDev 作为集成开发环境。产品发布时使用Py2exe进行打包。如今,在我的团队中,Pytho
- 再添加几个python资源
- 菜鸟学Python(9):给文件添加内容
- 在slackware 11.0为apache添加mod_python