yolila

Untitled

Apr 29th, 2011
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. import ctypes
  2. import _winreg
  3.  
  4. # See http://msdn.microsoft.com/en-us/library/aa385328(v=vs.85).aspx
  5. #: 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.
  6. INTERNET_OPTION_REFRESH = 37
  7. #: 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.
  8. INTERNET_OPTION_SETTINGS_CHANGED = 39
  9. # setup function
  10. Wininet = ctypes.windll.Wininet
  11. InternetSetOption = Wininet.InternetSetOptionW
  12.  
  13. HKEY_CURRENT_USER = _winreg.HKEY_CURRENT_USER
  14. SUB_KEY_PATH = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
  15.  
  16. def main():
  17.     hkey = _winreg.OpenKey(HKEY_CURRENT_USER, SUB_KEY_PATH, 0, _winreg.KEY_READ | _winreg.KEY_WRITE)
  18.     (ProxyEnabled, _) = _winreg.QueryValueEx(hkey, 'ProxyEnable')
  19.     _winreg.SetValueEx(hkey, 'ProxyEnable', 0, _winreg.REG_DWORD, not ProxyEnabled)
  20.     print 'enabled' if not ProxyEnabled else 'disabled'
  21.  
  22.     InternetSetOption(0, INTERNET_OPTION_REFRESH, 0, 0)
  23.     InternetSetOption(0, INTERNET_OPTION_SETTINGS_CHANGED, 0, 0)
  24.  
  25. if __name__ == '__main__':
  26.     main()
Advertisement
Add Comment
Please, Sign In to add comment