Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

realtime change IE proxysettings

by 2ge (Scribe)
on Apr 11, 2005 at 11:24 UTC ( [id://446566]=perlquestion: print w/replies, xml ) Need Help??

2ge has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I have to change IE proxy settings via perl interface in realtime, so they will be active. I searched the web for a long time, found something, coded too, but it doesn't work. I don't know how to "refresh" options - making them active. ok, my first goal is enable, or disable proxy in IE. Here is code:
use strict; use warnings; use Win32::TieRegistry( Delimiter=>"/", ArrayValues=>0 ); use Win32::API; #proxy in IE is disabled now my $regpath = 'HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVer +sion/Internet Settings/'; my $penable = $regpath . 'ProxyEnable'; $Registry->{$penable}= '0x00000001'; print my $pe = $Registry->{$penable}; #prints '0x00000001', so value i +s stored my $InternetSetOption = Win32::API->new("wininet", "InternetSetOption" +, [qw(N N N N)], 'N'); $InternetSetOption->Call(0, 39, 0, 0) || die "$!\n"; $InternetSetOption->Call(0, 37, 0, 0) || die "$!\n";
Please help. I am using windows 2003 server.
resources I've found: [1] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/w +ininet/wininet/internetsetoption.asp [2] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/w +ininet/wininet/option_flags.asp [3] http://aspn.activestate.com/ASPN/Mail/Message/pdk/1739515 [4] http://www.codeproject.com/internet/changeproxy1.asp

Replies are listed 'Best First'.
Re: realtime change IE proxysettings
by xorl (Deacon) on Apr 11, 2005 at 18:11 UTC
    Does this work: http://www.codeproject.com/internet/changeproxy1.asp Ok it's not a perl solution, but it's the best I can come up with. Besides if you can figure how to use Perl to access INTERNET_OPTION_SETTINGS_CHANGED and INTERNET_OPTION_REFRESH you'll have what you need.
      Hello Xorl,

      thanks for reply. After some time with playing that, I came with working solution, also I hope this helps to other people. So my code is:
      use strict; use warnings; use Win32::TieRegistry( Delimiter=>"/", ArrayValues=>0 ); use Win32::API; my %proxy_cfg = ( proxy_enable => 1, proxy_host => '149.121.12.4:8080', ); my $regpath = 'HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVe +rsion/Internet Settings/'; my $p_enable = $regpath . 'ProxyEnable'; my $p_server = $regpath . 'ProxyServer'; $Registry->{$p_enable} = [ pack("L",$proxy_cfg{proxy_enable}), "REG_DW +ORD" ]; $Registry->{$p_server} = $proxy_cfg{proxy_host} if $proxy_cfg{proxy_en +able}; my $InternetSetOption = Win32::API->new("wininet", "InternetSetOption" +, [qw(N N N N)], 'N'); $InternetSetOption->Call(0, 39, 0, 0) || die "$!\n"; $InternetSetOption->Call(0, 37, 0, 0) || die "$!\n"; print $proxy_cfg{proxy_enable} ? "Proxy enabled to $proxy_cfg{proxy_ho +st}\n" : "Proxy disabled\n";
Re: realtime change IE proxysettings
by Anonymous Monk on Dec 25, 2014 at 04:12 UTC

    This helps me a lot, thanks very much.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://446566]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found