Search for a registry key with a certain value

  • Thread starter Thread starter Eranga
  • Start date Start date
E

Eranga

Is there any way that we can serach for a registry key value with a
known data. For example if I want to find a registry value with the
known data"InternetSearch" how can I do it on C#?
for any help, thanks in advance.
 
Eranga,

The only way I know of would be to enumerate through all of the keys,
then all of the values, then all of the data for those values. It's a
tedious operation, but AFAIK, that is the only way to do it.

Hope this helps.
 
Eranga said:
Is there any way that we can serach for a registry key value with a
known data. For example if I want to find a registry value with the
known data"InternetSearch" how can I do it on C#?
for any help, thanks in advance.

Microsoft has a great (but not well known) tool for this - called LogParser
<http://www.microsoft.com/downloads/...6b-abf8-4c25-91b2-f8d975cf8c07&displaylang=en>
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.

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();
}
}
}


Hope this helps.
Willy.
 
Back
Top