Loading blog entries.. loading

Modify proxy settings using Powershell

Thursday, December 8, 2011 1:54 AM
Written by Wayne Ye
Font Size: S  M  L 

To use Live Messenger in the office, I always need to firstly disable my proxy settings, after Live Messenger launched, I need turn it back. Thus everytime I need to change that from "Internet Options -> Connections -> Lan Settings ->", check/uncheck the checkboxes, well, this task I need to do at least one time a day, I as a developer should achieve this in a more efficient and convenient way.

By overcoming one problem I wrote a snippet of Powershell cmdlet which does the job perfectly, the steps are:

  1. Update proxy settings to "Automatically detect settings".
  2. Launch Live Messenger.
  3. Update proxy settings to use proxy.

 The "one problem" I encountered and mentioned above is:

Where are the registry key(s) to store "Automatical configuration" section in Lan Settings.

I firstly tried to use Process Monitor by applying filter to only monitor my IE's process PID, while I did see it updated a number of places (see result outputed by procmon below), some of them are easy to be recognized such as "ProxyEnable", "ProxyOverride", etc, while I didn't see a obvious palce to store "Automatically detect settings".

 4:54:31.9881707 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings    SUCCESS    Type: REG_BINARY, Length: 385, Data: 46 00 00 00 3D 00 00 00 09 00 00 00 15 00 00 00
4:54:31.9883681 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable    SUCCESS    Type: REG_DWORD, Length: 4, Data: 0
4:54:31.9884340 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer    SUCCESS    Type: REG_SZ, Length: 44, Data: proxy.aus.hp.com:8080
4:54:31.9884568 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride    SUCCESS    Type: REG_SZ, Length: 60, Data: dummyA.com;dummyB.com;<local>
4:54:31.9886357 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings    SUCCESS    Type: REG_BINARY, Length: 385, Data: 46 00 00 00 B5 02 00 00 09 00 00 00 15 00 00 00
4:54:31.9899406 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable    SUCCESS    Type: REG_DWORD, Length: 4, Data: 0
4:54:31.9899612 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer    SUCCESS    Type: REG_SZ, Length: 44, Data: proxy.aus.hp.com:8080
4:54:31.9899892 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride    SUCCESS    Type: REG_SZ, Length: 60, Data: dummyA.com;dummyB.com;<local>
4:54:31.9901306 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings    SUCCESS    Type: REG_BINARY, Length: 385, Data: 46 00 00 00 B6 02 00 00 09 00 00 00 15 00 00 00
4:54:32.0357094 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Wpad\{65249C59-E027-4F0B-83FF-27DBB0B4E19E}_{B9E1413C-BF8C-444E-8FD0-105D9DD10F49}\WpadDecisionReason    SUCCESS    Type: REG_DWORD, Length: 4, Data: 0
4:54:32.0358754 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Wpad\{65249C59-E027-4F0B-83FF-27DBB0B4E19E}_{B9E1413C-BF8C-444E-8FD0-105D9DD10F49}\WpadDecisionTime    SUCCESS    Type: REG_BINARY, Length: 8, Data: 60 20 7E 00 87 B5 CC 01
4:54:32.0360316 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Wpad\{65249C59-E027-4F0B-83FF-27DBB0B4E19E}_{B9E1413C-BF8C-444E-8FD0-105D9DD10F49}\WpadDecision    SUCCESS    Type: REG_DWORD, Length: 4, Data: 1
4:54:32.0362007 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Wpad\{65249C59-E027-4F0B-83FF-27DBB0B4E19E}_{B9E1413C-BF8C-444E-8FD0-105D9DD10F49}\WpadNetworkName    SUCCESS    Type: REG_SZ, Length: 24, Data: cpqcorp.net
4:54:32.5961530 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\EnableAutodial    SUCCESS    Type: REG_DWORD, Length: 4, Data: 0
4:54:32.5961684 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\NoNetAutodial    SUCCESS    Type: REG_DWORD, Length: 4, Data: 0
4:54:32.5969457 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable    SUCCESS    Type: REG_DWORD, Length: 4, Data: 0
4:54:32.5969722 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer    SUCCESS    Type: REG_SZ, Length: 44, Data: proxy.aus.hp.com:8080
4:54:32.5969907 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride    SUCCESS    Type: REG_SZ, Length: 60, Data: dummyA.com;dummyB.com;<local>
4:54:32.5971154 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings    SUCCESS    Type: REG_BINARY, Length: 385, Data: 46 00 00 00 B7 02 00 00 09 00 00 00 15 00 00 00
4:54:32.9694553 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings    SUCCESS    Type: REG_BINARY, Length: 641, Data: 46 00 00 00 3E 00 00 00 09 00 00 00 15 00 00 00
4:54:32.9696389 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Wpad\WpadLastNetwork    SUCCESS    Type: REG_SZ, Length: 156, Data: {65249C59-E027-4F0B-83FF-27DBB0B4E19E}_{B9E1413C-BF8C-444E-8FD0-105D9DD10F49}
4:54:39.7267907 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable    SUCCESS    Type: REG_DWORD, Length: 4, Data: 0
4:54:39.7268135 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer    SUCCESS    Type: REG_SZ, Length: 44, Data: proxy.aus.hp.com:8080
4:54:39.7268366 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride    SUCCESS    Type: REG_SZ, Length: 60, Data: dummyA.com;dummyB.com;<local>
4:54:39.7270232 PM    iexplore.exe    2992    RegSetValue    HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings    SUCCESS    Type: REG_BINARY, Length: 641, Data: 46 00 00 00 BE 02 00 00 09 00 00 00 15 00 00 00

By a short time googling I found the answer on the awesome StackOverFlow, the "Automatical configuration" setting is stored in:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings

And the tricky part is, it is a Reg_Binary value, and the 9th binary number indicates the value of the two checkboxes, that is:

01 - neither of those 2 auto config boxes are checked

05 - just the Use automatic configuration script is checked

09 - just the Automatically detect settings is checked

0d - both of them are checked

 By knowing this I am ready to write my Cmdlet code, I pasted below:

 # 1.Modify proxy settings to "Automatically detect settings". i.e. Disable proxy
CD HKCU:\"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
Set-Itemproperty . DefaultConnectionSettings -Value ([byte[]](0x46,0x00,0x00,0x00,0x39,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x15,0x00,0x00,0x00,0x70,0x72,0x6F,0x78,0x79,0x2E,0x61,0x75,0x73,0x2E,0x68,0x70,0x2E,0x63,0x6F,0x6D,0x3A,0x38,0x30,0x38,0x30,0x1D,0x00,0x00,0x00,0x64,0x75,0x6D,0x6D,0x79,0x41,0x2E,0x63,0x6F,0x6D,0x3B,0x64,0x75,0x6D,0x6D,0x79,0x42,0x2E,0x63,0x6F,0x6D,0x3B,0x3C,0x6C,0x6F,0x63,0x61,0x6C,0x3E,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x68,0x74,0x74,0x70,0x3A,0x2F,0x2F,0x61,0x75,0x74,0x6F,0x63,0x61,0x63,0x68,0x65,0x2E,0x68,0x70,0x2E,0x63,0x6F,0x6D,0xA0,0x9D,0xC6,0x4C,0x6B,0xB5,0xCC,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x02,0x10,0xBB,0x56,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0xBB,0x56,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x10,0xBB,0x56,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00))

CD HKCU:\"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty . ProxyEnable 0

# 2.Launch Live Messenger
Start-Process "C:\Program Files (x86)\Windows Live\Messenger\msnmsgr.exe"

# 3.Sleep 10 seconds to allow live messenger signed in
Start-Sleep -s 10

# 4.Restore proxy back
CD HKCU:\"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
Set-Itemproperty . DefaultConnectionSettings -Value ([byte[]](0x46,0x00,0x00,0x00,0x39,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x00,0x00,0x00,0x70,0x72,0x6F,0x78,0x79,0x2E,0x61,0x75,0x73,0x2E,0x68,0x70,0x2E,0x63,0x6F,0x6D,0x3A,0x38,0x30,0x38,0x30,0x1D,0x00,0x00,0x00,0x64,0x75,0x6D,0x6D,0x79,0x41,0x2E,0x63,0x6F,0x6D,0x3B,0x64,0x75,0x6D,0x6D,0x79,0x42,0x2E,0x63,0x6F,0x6D,0x3B,0x3C,0x6C,0x6F,0x63,0x61,0x6C,0x3E,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x68,0x74,0x74,0x70,0x3A,0x2F,0x2F,0x61,0x75,0x74,0x6F,0x63,0x61,0x63,0x68,0x65,0x2E,0x68,0x70,0x2E,0x63,0x6F,0x6D,0xA0,0x9D,0xC6,0x4C,0x6B,0xB5,0xCC,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x02,0x10,0xBB,0x56,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0xBB,0x56,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x10,0xBB,0x56,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00))

CD HKCU:\"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty . ProxyEnable 1

C:
Echo Finished
Exit

Well, I put the sccript file on my desktop and named "Launch Live Messenger.ps1", every time I can simplt right click on it and select "Run with Powershell".

 

Permalink: http://wayneye.com/Blog/Modify-Proxy-Settings-Using-Powershell 8115 Views  6 Comments
Tag: Category:Programming»Windows Development»CMD/PowerShell

 

 


↓Comments↓

  WayneSunday, December 11, 2011 6:58 PM
I love the new theme:)
 
  WayneTuesday, December 13, 2011 6:38 AM
Test comment
 
  wayneTuesday, December 13, 2011 7:41 AM
Test cmt form android
 
  WayneWednesday, December 14, 2011 1:35 AM
hum
 
  WayneWednesday, December 14, 2011 1:39 PM
Ipad
 
  WayneMonday, June 25, 2012 9:23 AM
Test on mac
 

Your view point or opinion?
Nickname *
 
Gravatar *
Required (not shown), used only for displaying Gravatar and receiving future notification when new comment(s) posted on this blog.
 
Website/Blog
 
Content *
Current length:     Maximum allowed: charactors