WINDOWS TIP SHEET: Remote Registry, Unscripted

Query a registry remotely with this neat trick that involves no script at all.

By Jeffery Hicks

A question I often see in online forums is how to write a script to remotely query a registry. As much as I’m a big-time scripter, I’m also an advocate of the "right tool for the job" philosophy. If your needs are simple, you can get the information you need using the command line tool REG.EXE, which is now a part of Windows XP. For remote systems you are limited to querying HKEY_LOCAL_MACHINE and HKEY_USERS, which is basically what you’re limited to even using WMI.

To query are remote machine is as simple as passing a registry path and the name of the specific key you want to query:

Reg Query "\\GODOT\hklm\software\microsoft\windows NT\currentversion" /v CSDVersion

If the registry path has any spaces as in my example, be sure to enclose it in quotes. You’ll get a response like this:

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\software\microsoft\windows NT\currentversion
CSDVersion REG_SZ Service Pack 2

If you don’t specify a value with /v, then all the values in the path are enumerated. If you add /S all subkeys and values will also be enumerated. Of course, you also need appropriate credentials on the remote system.

If you have several computers you want to query, you could use the FOR command to enumerate a list, passing the computer name to the REG command. To see everything else you can do with REG run REG /?.

For a few systems, using REG this way is a fast and furious solution. However, when you start talking about querying more than a few machines, you need to start looking at a scripted solution. But I’ve done most of the work for you.

I have two batch files in my script library at http://www.jdhitsolutions.com/scripts that might help. One of them is a standalone query script. You can pass a computername as a parameter. The other one will process a list of computers. You’ll have to edit both for the registry information you want to query.

If you have any issues with them, post something in the Batch Files forum at ScriptingAnswers.com.

Comment: http://mcpmag.com/columns/article.asp?editorialsid=1795#post

Jeffery Hicks MCSE, MCSA, MCT is a senior network engineer with Visory Group. He's a contributing editor to ScriptingAnswers.com and the coauthor, with Don Jones, of "Advanced VBScript for Microsoft Windows Administrators" (Microsoft Press, http://tinyurl.com/g63nf ) and "PowerShell TFM" (SAPIEN Press, http://tinyurl.com/2v7dye ). Jeff is also the creator of several popular, script-related tools used for network and Exchange administration. He maintains a blog at http://jdhitsolutions.blogspot.com .