Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ctypes
- import _winreg
- # See http://msdn.microsoft.com/en-us/library/aa385328(v=vs.85).aspx
- #: Causes the proxy data to be reread from the registry for a handle. No buffer is required. This option can be used on the HINTERNET handle returned by InternetOpen. It is used by InternetSetOption.
- INTERNET_OPTION_REFRESH = 37
- #: Notifies the system that the registry settings have been changed so that it verifies the settings on the next call to InternetConnect. This is used by InternetSetOption.
- INTERNET_OPTION_SETTINGS_CHANGED = 39
- # setup function
- Wininet = ctypes.windll.Wininet
- InternetSetOption = Wininet.InternetSetOptionW
- HKEY_CURRENT_USER = _winreg.HKEY_CURRENT_USER
- SUB_KEY_PATH = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
- def main():
- hkey = _winreg.OpenKey(HKEY_CURRENT_USER, SUB_KEY_PATH, 0, _winreg.KEY_READ | _winreg.KEY_WRITE)
- (ProxyEnabled, _) = _winreg.QueryValueEx(hkey, 'ProxyEnable')
- _winreg.SetValueEx(hkey, 'ProxyEnable', 0, _winreg.REG_DWORD, not ProxyEnabled)
- print 'enabled' if not ProxyEnabled else 'disabled'
- InternetSetOption(0, INTERNET_OPTION_REFRESH, 0, 0)
- InternetSetOption(0, INTERNET_OPTION_SETTINGS_CHANGED, 0, 0)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment