Windows Tip Sheet

Remote Registry, Unscripted

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

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 like 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 then, you need to start looking at a scripted solution. But I’ve done most of the work for you.

Tech Help—Just An
E-Mail Away

Got a Windows, Exchange or virtualization question or need troubleshooting help? Or maybe you want a better explanation than provided in the manuals? Describe your dilemma in an e-mail to the MCPmag.com editors at [email protected]; the best questions get answered in this column and garner the questioner with a nifty Redmond T-shirt.

When you send your questions, please include your full first and last name, location, certifications (if any) with your message. (If you prefer to remain anonymous, specify this in your message, but submit the requested information for verification purposes.)

I have two batch files in my script library 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.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular