AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Internet Explorer / Windows proxy function

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Superfraggle



Joined: 02 Nov 2004
Posts: 773
Location: London, UK

PostPosted: Mon Jul 16, 2007 4:28 pm    Post subject: Internet Explorer / Windows proxy function Reply with quote

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.

Code:
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 Very Happy

Thanks also to engunneer and manauser for simplifying and enhancing Very Happy

Any comments, let me know Very Happy
_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Last edited by Superfraggle on Tue Jul 17, 2007 12:00 am; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger
ManaUser



Joined: 24 May 2007
Posts: 900

PostPosted: Mon Jul 16, 2007 9:19 pm    Post subject: Reply with quote

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:
Code:
setproxy(address = "",state = "")
so you can leave off unneed paramters instead of having to use "".
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 773
Location: London, UK

PostPosted: Mon Jul 16, 2007 10:12 pm    Post subject: Reply with quote

should work with any proxy to pass the port just use address:port.
it will affect URLdownloadtofile I believe too.

Quote:
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
Back to top
View user's profile Send private message MSN Messenger
engunneer



Joined: 30 Aug 2005
Posts: 6551
Location: Pacific Northwest, US

PostPosted: Mon Jul 16, 2007 10:31 pm    Post subject: Reply with quote

the function itself - optional parameters http://www.autohotkey.com/docs/Functions.htm#optional
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Superfraggle



Joined: 02 Nov 2004
Posts: 773
Location: London, UK

PostPosted: Mon Jul 16, 2007 10:37 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
engunneer



Joined: 30 Aug 2005
Posts: 6551
Location: Pacific Northwest, US

PostPosted: Mon Jul 16, 2007 11:50 pm    Post subject: Reply with quote

yes, that's a good way.

Code:

setproxy("address.proxy.com",)

should be
Code:

setproxy("address.proxy.com")


and you can make it even better for lazy programmers:
Code:

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.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Superfraggle



Joined: 02 Nov 2004
Posts: 773
Location: London, UK

PostPosted: Tue Jul 17, 2007 12:01 am    Post subject: Reply with quote

Thanks to both of you, have made the changes to relect both enhancements now.
_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle
Back to top
View user's profile Send private message MSN Messenger
HCProfessionals



Joined: 19 Jun 2007
Posts: 106

PostPosted: Mon Feb 18, 2008 2:15 am    Post subject: Reply with quote

So, who wants to give me a list of safe proxies? If you do, PM them to me Very Happy
Back to top
View user's profile Send private message
badmojo



Joined: 11 Nov 2005
Posts: 140

PostPosted: Tue May 06, 2008 2:51 am    Post subject: Reply with quote

just wondering, how to make this script accept parameters? e.g setproxy 1 sets the proxy while setproxy 0 turns off.
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 773
Location: London, UK

PostPosted: Tue May 06, 2008 3:20 am    Post subject: Reply with quote

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

Code:

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
Back to top
View user's profile Send private message MSN Messenger
badmojo



Joined: 11 Nov 2005
Posts: 140

PostPosted: Tue May 06, 2008 3:46 am    Post subject: Reply with quote

thanks Superfraggle, that is close to what i want but i am trying to add something like this:

Code:
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?
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 773
Location: London, UK

PostPosted: Tue May 06, 2008 6:16 am    Post subject: Reply with quote

Code:
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
Back to top
View user's profile Send private message MSN Messenger
badmojo



Joined: 11 Nov 2005
Posts: 140

PostPosted: Tue May 06, 2008 6:36 am    Post subject: Reply with quote

Superfraggle wrote:
Percent signs are not needed inside function calls.

thanks, Superfraggle! you've nailed it. Smile
Back to top
View user's profile Send private message
me
Guest





PostPosted: Wed May 14, 2008 2:09 am    Post subject: ca Reply with quote

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?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group