python3操作注册表设置/取消IE代理
import io, sys, time, re, os import winreg def enableProxy(IP, Port): proxy = IP + ":" + str(Port) xpath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings" try: key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, xpath, 0, winreg.KEY_WRITE) winreg.SetValueEx(key, "ProxyEnable", 0, winreg.REG_DWORD, 1) winreg.SetValueEx(key, "ProxyServer", 0, winreg.REG_SZ, proxy) except Exception as e: print("ERROR: " + str(e.args)) finally: None def disableProxy(): proxy = "" xpath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings" try: key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, xpath, 0, winreg.KEY_WRITE) winreg.SetValueEx(key, "ProxyEnable", 0, winreg.REG_DWORD, 0) winreg.SetValueEx(key, "ProxyServer", 0, winreg.REG_SZ, proxy) except Exception as e: print("ERROR: " + str(e.args)) finally: None def main(): proxyIP = "10.10.1.2" proxyPort = 123 try: disableProxy()
enableProxy(proxyIP, proxyPort) except Exception as e: print("ERROR: " + str(e.args)) finally: pass if __name__ == '__main__': main()
本文来自博客园,作者:方倍工作室,转载请注明原文链接:https://www.cnblogs.com/txw1958/archive/2012/06/15/python3-ie-proxy.html