Toggle between two registry settings with another simple script

Last Updated on July 27, 2017 by Dave Farquhar

On the heels of yesterday, the same technique that swapped hosts files can be adapted to toggle registry settings too. The registry, if you’re not familiar, is a central database that stores Windows configuration settings.

Perhaps you want to be able to toggle your screen saver timeout from the default of 1500 to a value of 9999. That way, you can easily choose between the screen saver interrupting you or not. I run into a problem when running certain emulators with the screen saver timing out on me; this would solve the problem.

So, create a couple of .reg files to start with.

screensaver.active
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Control Panel\Desktop] "ScreenSaveTimeOut"="1500"

screensaver.2.reg
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Control Panel\Desktop] "ScreenSaveTimeOut"="9999"

Next, create this batch file.
if exist screensaver.1.reg goto One
if exist screensaver.2.reg goto two
:One
reg import screensaver.1.reg
ren screensaver.active screensaver.2.reg
ren screensaver.1.reg screensaver.active
goto done
:two
reg import screensaver.2.reg
ren screensaver.active screensaver.1.reg
ren screensaver.2.reg screensaver.active
:done

And that’s all there is to it. Running the batch file will change the screensaver timeout setting for you, automatically.

Toggling network settings

Another possible good use for this would be for laptops, if you want to toggle between one set of TCP/IP settings and another. Perhaps you use a fixed IP address at the office, and DHCP on the road. Or perhaps you want to toggle between your local ISP’s DNS servers and Google or Open DNS servers.

You can do it by navigating to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318} in Regedit, then locate the adapter ID that has your active TCP/IP settings. Then export that tree. Next, change the TCP/IP settings to your alternates–you can use the control panel if you prefer, since that’s much easier than navigating the registry–and then export again.

Modify the script above to use appropriate filenames–say, network.1.reg and network.2.reg–and then you can toggle network settings with a simple batch file, too.
If you found this post informative or helpful, please share it!

2 thoughts on “Toggle between two registry settings with another simple script

  • September 23, 2011 at 2:45 pm
    Permalink

    Any way to insert an ECHO or PAUSE command to let us know which reg file has been entered into the registry?

    • September 24, 2011 at 11:07 am
      Permalink

      Certainly. You can put a pause after the last line, and an echo command saying whatever you want, right before the goto statements.

Comments are closed.