python添加Windows环境变量

1.cmd中添加方式

SET PATH=%PATH%;c:\Program Files (x86)\Wireshark

注:如上代码添加c:\Program Files (x86)\Wireshark至Windows环境变量中

但在python中使用os.system()函数却无法执行该命令,目前还未找到原因。

 

2.python操作Windows注册表进行更改

import _winreg as wg
key_test = wg.OpenKey(wg.HKEY_LOCAL_MACHINE,r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment",0,wg.KEY_ALL_ACCESS)
path_str = wg.QueryValueEx(key_test,'path')
path_str_new = path_str[0] + ';' + 'c:\Program Files (x86)\Wireshark'
wg.SetValueEx(key_test,'path','',path_str[1],path_str_new)
wg.FlushKey(key_test)
wg.CloseKey(key_test)

注:path_str的值为(u'C:\\Python27\\;C:\\Python27\\Scripts;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%systemroot%\\System32\\WindowsPowerShell\\v1.0\\;%systemroot%\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;;"C:\\Program Files (x86)\\Spirent Communications\\Spirent TestCenter 4.68\\Layer 4-7 Application";C:\\Program Files\\TortoiseSVN\\bin;C:\\Python27;c:\\Program Files (x86)\\Wireshark', 2)

 

 

转载于:https://www.cnblogs.com/hester/p/7883453.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值