I am writing a program to automatically switch my proxy address based on the network I am connected to.
I have so far got everything to work except the part that I have
You just need modify the value:
Registry Key : HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ DWORD AutoDetect = 0 or 1
See this link.