Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Internet Explorer / Windows proxy function


  • Please log in to reply
22 replies to this topic
Superfraggle
  • Members
  • 1019 posts
  • Last active: Sep 25 2011 01:06 AM
  • Joined: 02 Nov 2004
Thought I would share this in case anyone else need it, allows quick changing of the proxy settings within internet explorer, and updates all windows to inform them that they have changed.

Ive included a few examples at the top, but generally usage is

setproxy("Address","state")

where address is the address to change it too, and state can be either on, off or toggle.

setproxy("address.proxy.com") 
setproxy("address.proxy2.com","ON") 
setproxy("address.proxy.com","OFF") 
setproxy() 
return 

setproxy(address = "",state = ""){ 
if (address = "") and (state = "") 
    state = TOGGLE 

if address
    regwrite,REG_SZ,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,ProxyServer,%address%
  if (state ="ON")
    regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,1
  else if (state="OFF")
    regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,0
  else if (state = "TOGGLE")
    {
      if regread("HKCU","Software\Microsoft\Windows\CurrentVersion\Internet Settings","Proxyenable") = 1
        regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,0
      else if regread("HKCU","Software\Microsoft\Windows\CurrentVersion\Internet Settings","Proxyenable") = 0
        regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,1 
    }
  dllcall("wininet\InternetSetOptionW","int","0","int","39","int","0","int","0")
  dllcall("wininet\InternetSetOptionW","int","0","int","37","int","0","int","0")
  Return
}

RegRead(RootKey, SubKey, ValueName = "") {
	RegRead, v, %RootKey%, %SubKey%, %ValueName%
	Return, v
}

Thanks to Titan for the regread function also included here :D

Thanks also to engunneer and manauser for simplifying and enhancing :D

Any comments, let me know :D
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle

ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
Nice work. This should work with a local proxy too, right? (e.g. localhost:2468 or whatever.) I normally use a proxy to surf the web (it blocks pop-ups, helps protect privacy and such) but I don't have IE set up to use it, so this would definitely come in handy if I want AHK to go through it.

A small sugestion. Why not do this:
setproxy(address = "",state = "")
so you can leave off unneed paramters instead of having to use "".

Superfraggle
  • Members
  • 1019 posts
  • Last active: Sep 25 2011 01:06 AM
  • Joined: 02 Nov 2004
should work with any proxy to pass the port just use address:port.
it will affect URLdownloadtofile I believe too.

A small sugestion. Why not do this:Code (Copy):
setproxy(address = "",state = "")
so you can leave off unneed paramters instead of having to use "".


Not quite sure what you mean there, you mean in the function itself, or the function call??
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
the function itself - optional parameters <!-- m -->http://www.autohotke...ns.htm#optional<!-- m -->

Superfraggle
  • Members
  • 1019 posts
  • Last active: Sep 25 2011 01:06 AM
  • Joined: 02 Nov 2004
Thanks engunneer like that then?

This was my first real function that I had made, been using lots of gosubs till now.
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
yes, that's a good way.

setproxy("address.proxy.com",)
should be
setproxy("address.proxy.com")

and you can make it even better for lazy programmers:
setproxy("address.proxy.com",)
setproxy("address.proxy2.com","ON")
setproxy("address.proxy.com","OFF")
setproxy()
return

setproxy(address = "",state = ""){
  if (address = "") and (state = "")
    state = TOGGLE

  if address
    regwrite,REG_SZ,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,ProxyServer,%address%
  if (state ="ON")
    regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,1
  else if (state="OFF")
    regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,0
  else if (state = "TOGGLE")
    {
      if regread("HKCU","Software\Microsoft\Windows\CurrentVersion\Internet Settings","Proxyenable") = 1
        regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,0
      else if regread("HKCU","Software\Microsoft\Windows\CurrentVersion\Internet Settings","Proxyenable") = 0
        regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,1
    }
  dllcall("wininet\InternetSetOptionW","int","0","int","39","int","0","int","0")
  dllcall("wininet\InternetSetOptionW","int","0","int","37","int","0","int","0")
  Return
}

RegRead(RootKey, SubKey, ValueName = "") {
   RegRead, v, %RootKey%, %SubKey%, %ValueName%
   Return, v
}

And thank ManaUser, he caught it, I just knew how to clarify.

Superfraggle
  • Members
  • 1019 posts
  • Last active: Sep 25 2011 01:06 AM
  • Joined: 02 Nov 2004
Thanks to both of you, have made the changes to relect both enhancements now.
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle

HCProfessionals
  • Members
  • 179 posts
  • Last active: Jul 31 2013 12:49 AM
  • Joined: 18 Jun 2007
So, who wants to give me a list of safe proxies? If you do, PM them to me :D

badmojo
  • Members
  • 204 posts
  • Last active: Jul 23 2014 01:39 AM
  • Joined: 11 Nov 2005
just wondering, how to make this script accept parameters? e.g setproxy 1 sets the proxy while setproxy 0 turns off.

Superfraggle
  • Members
  • 1019 posts
  • Last active: Sep 25 2011 01:06 AM
  • Joined: 02 Nov 2004
Assuming you dont want to change the address, only the on/off state use this.

setproxy(1)
return

setproxy(state = "Toggle"){

if (state ="ON" or state = 1)
regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,1
  else if (state="OFF" or state = 0)
    regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,0
  else if (state = "TOGGLE")
    {
      if regread("HKCU","Software\Microsoft\Windows\CurrentVersion\Internet Settings","Proxyenable") = 1
        regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,0
      else if regread("HKCU","Software\Microsoft\Windows\CurrentVersion\Internet Settings","Proxyenable") = 0
        regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,1
    }
  dllcall("wininet\InternetSetOptionW","int","0","int","39","int","0","int","0")
  dllcall("wininet\InternetSetOptionW","int","0","int","37","int","0","int","0")
  Return
}

RegRead(RootKey, SubKey, ValueName = "") {
   RegRead, v, %RootKey%, %SubKey%, %ValueName%
   Return, v
}

Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle

badmojo
  • Members
  • 204 posts
  • Last active: Jul 23 2014 01:39 AM
  • Joined: 11 Nov 2005
thanks Superfraggle, that is close to what i want but i am trying to add something like this:

If 0 < 1
  ExitApp
  
proxystate = %1%
setproxy(%proxystate%)
return

;...
;rest of the code here
so that i can compile and run the script from command-line or the run-box. but somehow the %1% doesn't seem to have any effect. can you help with this?

Superfraggle
  • Members
  • 1019 posts
  • Last active: Sep 25 2011 01:06 AM
  • Joined: 02 Nov 2004
If 0 < 1
  ExitApp
 
proxystate = %1%
setproxy(proxystate)
return

;...
;rest of the code here

Percent signs are not needed inside function calls.
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle

badmojo
  • Members
  • 204 posts
  • Last active: Jul 23 2014 01:39 AM
  • Joined: 11 Nov 2005

Percent signs are not needed inside function calls.

thanks, Superfraggle! you've nailed it. :)

me
  • Guests
  • Last active:
  • Joined: --
can u set this to jus hide the proxy to get past blocked sites??? jus copy the code so i dont hav to change anything cuz i hav no clue wut to do lolz can u jus copy the code so i can paste it and get past blocked sites?

alexbiz
  • Members
  • 4 posts
  • Last active: Oct 02 2009 07:43 PM
  • Joined: 18 Sep 2009

Assuming you dont want to change the address, only the on/off state use this.


I used your code and made a version with a VERY BASIC GUI, which could help.

Gui, Add, Button, x46 y20 w100 h30 Gon , Proxy ON
Gui, Add, Button, x46 y60 w100 h30 Goff , Proxy OFF
Gui, Add, Button, x46 y100 w100 h30 Ggtfo , Exit
; Generated using SmartGUI Creator 4.0
Gui, Show, x129 y99 h146 w194, Proxy Status
Return

on:
setproxy("ON") 
return


off:
setproxy("OFF") 
return


setproxy(state="")
{ 
	if(state = "")
		state = "ON"
	if (state ="ON")
    		regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,1
  	else if (state="OFF")
    		regwrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,Proxyenable,0

  	dllcall("wininet\InternetSetOptionW","int","0","int","39","int","0","int","0")
  	dllcall("wininet\InternetSetOptionW","int","0","int","37","int","0","int","0")
  	Return
}
;;----------------------------------------------------------
;;    Function RegRead
;;----------------------------------------------------------
RegRead(RootKey, SubKey, ValueName = "") {
   RegRead, v, %RootKey%, %SubKey%, %ValueName%
   Return, v
}

gtfo:
ExitApp

GuiClose:
ExitApp

and now I'm trying to make it work with firefox.. but the main issue is that firefox doesn't work the same way. You have to modify prefs.js in C:\Documents and Settings\%username%\Application Data\Mozilla\Firefox\Profiles\yiji8soy.default