Script to Enable/Disable proxy

PowerShell Script

Today I was working with one application where I needed to test application settings multiple times with proxy on and with proxy off. I wanted to have a script that I can run to change between this 2 states and I also wanted to know last state of proxy (if it’s on or off). I decided to write PowerShell script (as I do for almost all my problems :D).

First thing I done, was to find correct registry key. It is under Curent User hive: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections. Binary value that changes this setting is named DefaultConnectionSettings. We need to look for a value of 9th byte:

Decimal value | Hexadecimal value –> Description

  • 1 | 01 –> All unchecked
  • 3 | 03 –> Use a Proxy Server…” (2) checked
  • 9 | 09 –> “Automatically detect settings” (8) checked
  • 11 | 0b (1+8+2) –> “Automatically detect settings” (8) and “Use a Proxy Server…” (2) checked
  • 13 | 0d (1+8+4) –> “Automatically detect settings” (8) and “Use Automatic configuration script” (4) checked
  • 15 | 0f (1+8+4+2) –> All three check box are checked

PowerShell Script:

$RegKey = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections'
$Settings = (Get-ItemProperty -Path $RegKey).DefaultConnectionSettings
 
if ($Settings[8] -eq 1) {
    $Settings[8] = 3
    Set-ItemProperty -path $regKey -name DefaultConnectionSettings -value $Settings
    msg console /time:3 "Proxy is now enabled"
}
 
elseif ($Settings[8] -eq 3) {
    $Settings[8] = 1
    Set-ItemProperty -path $regKey -name DefaultConnectionSettings -value $Settings
    msg console /time:3 "Proxy is now disabled"
}
 
else {
    $Settings[8] = 3
    Set-ItemProperty -path $regKey -name DefaultConnectionSettings -value $Settings
    msg console /time:3 "Proxy is now enabled"
}

So, how does the script work? It gets DefaultConnectionSettings value from $RegKey and store it in $Settings. Then it checks for value in 9th byte:
– If it’s 1 (all checkboxes are unchecked), it changes to 3 (proxy on) and other way around (from 3 to 1).
– If the value is different, it changes to 3 (proxy on).

For all situations we get 3 second message with proxy status.

2 Comments

  1. Thanks for sharing!

    Reply
  2. Doctors have many challenges to face as they are perennially surrounded by patients, diseases, hospital duties and over-extended or odd shift timings. Universally, doctor is considered to be a noble profession and respectable one at that, but a doctor also has to work under immense pressures, emotional strains and other physical challenges.

    A regular physician like most of us at some point face will have to deal with personal situations such as important family affairs, family holidays, sickness or pregnancy that may force them to abandon medical duties. At the same time, a hospital or a healthcare facility is also constantly faced with emergency situations that demand all hands on deck round-the-clock. Therefore, every hospital, clinic or nursing home is compelled to hire locum tenens or substitute doctor in order to keep the staffing under control at all times.

    In fact, locum doctors are the most valuable asset for the medical community because they provide quality medical care and act as a helping-hand in emergency situations when the medical facilities need them the most.

    Unlike regular or permanent doctors, locum doctor jobs are also ideal career options for medical interns and graduates because they offer a wide array of medical exposure in varied medical specialties, work cultures and healthcare systems. Locum jobs are challenging and flexible, thus an increasing number of medical professionals have benefitted from these jobs, so whether one is looking for a family physicians position or in a hospital or in a clinic, locum jobs for doctors are available at all levels and in different healthcare systems.

    In addition, being a locum doctor gives a medical professional the control over their working hours, location of work and choice of area of specialisation. Technically, locum positions are not restricted to general physicians but they are also extended to other fields of medical specialisations such as cardiology, neurology and many more.

    Travelling can be an integral part of locum jobs, and these distinctive features are a boon for many dedicated medical professionals who are eager to expand their medical careers with loads of multi-cultural medical experiences. The fact that locum agencies in the UK recruit tens of thousands of locums from across the globe in various NHS hospitals, private clinics, nursing homes and other public hospitals speaks volume of the popularity of locum jobs.

    Locating or getting a locum tenens job is a simple task as long as you are registered with one of the many reputable locum agencies. These agencies act as the middle man between locum tenens and medical facilities, and they also look after all the details pertaining to travel for locum tenens, accommodation and the nature of locum work.

    Thus, maintaining a healthy locum doctor-agency relationship benefits both the parties, and it also increases the probability of getting recommendable employment opportunities and businesses or vice-versa.

    Reply

Your email address will not be published.