"Eranga" <km***@yahoo.co m> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
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"InternetSe arch" how can I do it on C#?
for any help, thanks in advance.
*** Sent via Developersdex http://www.developersdex.com ***
Microsoft has a great (but not well known) tool for this - called LogParser
<http://www.microsoft.c om/downloads/details.aspx?Fa milyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&di splaylang=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.d ll"
/out:Interop.MSU til.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 RegistryInputFo rmat = Interop.MSUtil. COMRegistryInpu tContextClass;
using RegRecordSet = Interop.MSUtil. ILogRecordset;
class Program
{
public static void Main()
{
RegRecordSet rs = null;
try
{
LogQuery qry = new LogQuery();
RegistryInputFo rmat registryFormat = new RegistryInputFo rmat();
string query = @"SELECT Path from \HKLM\SOFTWARE\ Microsoft where
Value='VisualSt udio'";
rs = qry.Execute(que ry, registryFormat) ;
for(; !rs.atEnd(); rs.moveNext())
Console.WriteLi ne(rs.getRecord ().toNativeStri ng(","));
}
finally
{
rs.close();
}
}
}
Hope this helps.
Willy.