Recipe 9.6. Searching the RegistryProblemYou want to search the registry for the occurrence of a string or number. SolutionUsing a graphical user interface
Using a command-line interfaceOn Windows Server 2003, use the reg command to search the registry: > reg query \\<ServerName>\<RegKey> /f <ValueName> /s /k For instance, the following command searches recursively under the specified registry key for all values that contain "Run": > reg query \\server01\HKLM\Software\Microsoft /f Run /s /k Replace the /k switch with /d to perform the same search, but matching only value data (and not key names). Run reg query /? for the complete list of search options. The version of reg included with the Windows 2000 Resource Kit does not have all of the search capabilities of the one included with Windows Server 2003. But you can use the regfind utility from the Windows 2000 Resource Kit to perform similar searches. Here is the syntax: > regfind -m \\<ServerName> -p <RegKey> -n "<ValueName>" For example: > regfind -m \\server01 -p HKEY_LOCAL_MACHINE\Software\Microsoft -n "Run" View the regfind command-line help for all of the search options. Using VBScriptUnfortunately, the StdRegProv WMI Provider doesn't support searching the registry. Your only options to search the registry via VBScript would be to enumerate over all the keys and values you want to search against (very inefficient), shell out to a command-line utility such as reg (see Recipe Recipe 9.5 for an example of how to do this), or find a third-party ActiveX control that implements a registry search interface that can be used by scripting languages. DiscussionThe registry contains a significant amount of data. Don't be surprised if your initial search matches a lot of different keys or values that you weren't intending. This is especially true if you search across a whole hive or all of the hives. Try to restrict your search to a specific key when possible. |