We know that Windows Registry is heart of the Windows Operating Systems. Many non-technical users will get scared, if they hear the name registry. In Windows, whatever we do in the graphical user interface (GUI) can be done by changing some values in the registry or even we can do many things which can’t be done directly through graphical user interfaces. Many of you guys will know how to play around with Windows Registry by using Regedit.exe (Registry Editor). Discussion of playing around with Windows Registry using Windows Registry Editor (Regedit.exe) is beyond the scope of this article. In this article, we are going to introduce you to a windows command line registry tool using which you can automate windows registry manipulations. Before getting into actual topic, let us discuss few basic things about Windows Registry.
What is Windows Registry?
Windows Registry is a database which stores configuration settings and options on Microsoft Windows Operating Systems. It contains settings for windows components as well the applications running on Windows.
I hope explaining Windows Registry with a small example would help you to understand Windows registry better. In almost all the applications running in windows, you would have seen some kind of options to set. When you set those options, it remains unchanged until you change it. Have you ever wondered where these settings are getting stored? 99% of those settings are stored in Windows Registry. To understand Windows Registry better, try changing few settings for some application (make sure you are comfortable with that application and changes you are making in registry). Changing the values in Windows Registry will have the impact in the application. Sometimes even your application will get corrupted, if you change the values in Windows Registry. Microsoft supplies Registry Editor with Windows. This is can be opened by typing regedit.exe in ‘Run’ dialog.
Microsoft supplies reg.exe program with Windows. Using this tool, you will be able to do anything which you can do using Windows Registry Editor. It is a command line tool.
Accessing Remote Machine’s Registry with Reg.exe:
You can access/manipulate remote machine’s registry using reg.exe.
Querying the Registry:
You can query the registry using the below command,
REG QUERY HKLM\Software\Microsoft
This will list all the sub keys under “HKLM\Software\Microsoft”. HKLM is an abbreviation of HKEY_LOCAL_MACHINE.
To query the remote machine’s registry add the hostname after the “REG QUERY” as below,
REG QUERY \\ABC\HKLM\Software\Microsoft
Here ‘ABC’ is a hostname. The above command will list all the sub keys under “HKLM\Software\Microsoft” from ‘ABC’.
Adding Values to Registry:
You can add values (value or keys) using REG ADD command.
Deleting Value from Registry:
You can delete values (value or keys) using REG DELETE command.
Comparing Registry Values:
You can compare registry values or keys using REG COMPARE command.
Importing Registry Values:
You can import registry values from .reg file using REG IMPORT command.
Exporting Registry Values:
You can export registry values to .reg file using REG EXPORT command.
Automating Registry Manipulations with Reg.exe:
Since we have command line tool to play around with Windows Registry, it is very easy to automate Windows Registry operations. This can be automated by putting these commands into Windows Batch File (.bat). This will be very helpful for Windows Administrators and Test Automation Engineers.
Let us discuss with an example. Below command creates a key by name “Testkey” under “HKLM\Software\”.
REG ADD HKLM\Software\TestKey
Now put this command bit differently (as shown below) into a batch file and run it.
cmd.exe /c “REG ADD \\ABC\HKLM\Software\TestKey”
“cmd.exe /c” option will launch MS DOS command prompt and execute the specified command and it will terminate.
I hope with this example, you guys will be able to find solutions to your problems. If you are not able to solve your problems, then send your queries to firstname.lastname@example.org. I would be happy to assist you.
Applies to: This article applies to all 32/64 bit editions of Windows XP/Windows 2003/Windows Vista/Windows 2008/Windows 7 and Windows 2008 R2.