python 版本切换脚本(切记根据自己的需求更改,出错自己负责)
来源:互联网 发布:电子技术仿真软件 编辑:程序博客网 时间:2024/06/07 03:33
# -*- coding: utf-8 -*-
author = 'nathan'
import os
import re
import getpass
import sys
import time
import _winreg
import ctypes
import win32api
import win32gui, win32con
def version_change():
#注册表去查看自己所需要修改的位置,_winreg.KEY_ALL_ACCESS是SAM属性,win7,win8需先在注册表中开放用户权限
hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\ControlSet001\Control\Session Manager\Environment',0,_winreg.KEY_ALL_ACCESS)
# get the current value
value, typ = _winreg.QueryValueEx (hKey, 'path')
#print value
try:
value, typ = _winreg.QueryValueEx (hKey, 'current_py_version')
except:
print r"新建系统环境变量current_py_version"
#newKey = _winreg.CreateKey(hKey,"current_py_version")
#_winreg.SetValue(newKey,"ValueName",0,"ValueContent")
_winreg.SetValueEx(hKey, "current_py_version", 0, typ, ''.join('C:\Python27') )
print'---更改current_py_version中----'
value, typ = _winreg.QueryValueEx (hKey, 'current_py_version')
print "原本为:",value
if (value=='C:\Python27'):
_winreg.SetValueEx(hKey, "current_py_version", 0, typ, ''.join(r'C:\Users\nathan\AppData\Local\Programs\Python\Python35') )
else:
_winreg.SetValueEx(hKey, "current_py_version", 0, typ, ''.join(r'C:\Python27') )
value, typ = _winreg.QueryValueEx (hKey, 'current_py_version')
print "现版本为",value
rc, dwReturnValue = win32gui.SendMessageTimeout(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, "Environment", win32con.SMTO_ABORTIFHUNG, 5000)
version_change()
path = os.environ['path']
author = 'nathan'
import os
import re
import getpass
import sys
import time
import _winreg
import ctypes
import win32api
import win32gui, win32con
def version_change():
#注册表去查看自己所需要修改的位置,_winreg.KEY_ALL_ACCESS是SAM属性,win7,win8需先在注册表中开放用户权限
hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\ControlSet001\Control\Session Manager\Environment',0,_winreg.KEY_ALL_ACCESS)
# get the current value
value, typ = _winreg.QueryValueEx (hKey, 'path')
#print value
try:
value, typ = _winreg.QueryValueEx (hKey, 'current_py_version')
except:
print r"新建系统环境变量current_py_version"
#newKey = _winreg.CreateKey(hKey,"current_py_version")
#_winreg.SetValue(newKey,"ValueName",0,"ValueContent")
_winreg.SetValueEx(hKey, "current_py_version", 0, typ, ''.join('C:\Python27') )
print'---更改current_py_version中----'
value, typ = _winreg.QueryValueEx (hKey, 'current_py_version')
print "原本为:",value
if (value=='C:\Python27'):
_winreg.SetValueEx(hKey, "current_py_version", 0, typ, ''.join(r'C:\Users\nathan\AppData\Local\Programs\Python\Python35') )
else:
_winreg.SetValueEx(hKey, "current_py_version", 0, typ, ''.join(r'C:\Python27') )
value, typ = _winreg.QueryValueEx (hKey, 'current_py_version')
print "现版本为",value
rc, dwReturnValue = win32gui.SendMessageTimeout(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, "Environment", win32con.SMTO_ABORTIFHUNG, 5000)
version_change()
path = os.environ['path']
print path
解决了注册表更新的问题,不过需要使用到win32
阅读全文
0 0
- python 版本切换脚本(切记根据自己的需求更改,出错自己负责)
- 为自己的因果负责
- 对自己的人生负责
- 为自己的人生负责
- 自定义Toast 可以根据自己的需求 设置显示时间
- 根据自己的需求改进了下lavalamp插件
- 自定义Toast 可以根据自己的需求 设置显示时间
- 做认真的人为自己负责
- iOS-自定义下拉刷新上拉加载(可根据自己的需求改)
- 对自己负责
- 为自己负责
- 为自己负责(8.24)
- 我自己负责
- 对自己负责
- [Python][自己写的杀病毒脚本]
- 操作Android中联系人,通话记录,短息,的URI,和具体的查询语句,字段注解。(根据自己需求)
- 请一定要对自己负责
- [6.8] 对自己生命负责
- jxbrowser 监听所有网络请求 jxbrowser 系列教程2
- Ubuntu 14.04安装和使用python3.5
- 480. Sliding Window Median
- spark入门(4)----scala扫盲(1)
- Input实现下拉框多选
- python 版本切换脚本(切记根据自己的需求更改,出错自己负责)
- sql server如何对表进行查看锁和解锁
- SIGABRT的可能原因
- 颜色格式转换: 最简单的基于FFmpeg的libswscale的示例(YUV转RGB)
- Java基础面试题
- Mac OS X系统下adb调试Android手机的方法
- 【scala】Scala中lazy关键字的使用和理解
- PHP开发增删改查
- IE浏览器下ajax缓存导致数据不更新的解决方法