Click here to Skip to main content
15,922,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to search for a string value in the windows registry? If it is, how?
Is it possible with log parser to search for a string value that contains a value and return the result like
HKEY_CURRENT_USER\...\*value name* = *value* ?
Posted
Updated 8-Dec-09 10:01am
v2

1 solution

There are only two options.

1. Use the Microsoft.Win32.Registry class to iterate through all the keys and subkeys until you find the value you are looking for.

2. Microsoft has a great (but not well known) tool for this - called LogParser.

It uses a SQL engine to query all kind of text based data like the Registry, the Filesystem, the eventlog, AD etc... To be usable from C#, you need to build an Interop Assembly from the Logparser.dll COM server using following (adjust LogParser.dll path) command.

tlbimp "C:\Program Files\Log Parser 2.2\LogParser.dll" /out:Interop.MSUtil.dll
Following is a small sample, that illustrates how to query for the Value 'VisualStudio' in the \HKLM\SOFTWARE\Microsoft tree.

C#
using System;
using System.Runtime.InteropServices;
using LogQuery = Interop.MSUtil.LogQueryClass;
using RegistryInputFormat = Interop.MSUtil.COMRegistryInputContextClass;
using RegRecordSet = Interop.MSUtil.ILogRecordset;

class Program
{
  public static void Main()
  {
    RegRecordSet rs = null;
    try
    {
      LogQuery qry = new LogQuery();
      RegistryInputFormat registryFormat = new RegistryInputFormat();
      string query = @"SELECT Path from \HKLM\SOFTWARE\Microsoft where Value='VisualStudio'";
      rs = qry.Execute(query, registryFormat);
      for(; !rs.atEnd(); rs.moveNext())
        Console.WriteLine(rs.getRecord().toNativeString(","));
    }
    finally
    {
      rs.close();
    }
  }
}


NB// This answer is quoted from stackoverflow.com[^] but copied here for the benefit of the code snippet.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900