By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,009 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,009 IT Pros & Developers. It's quick & easy.

Search for a registry key with a certain value

P: n/a

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.
*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Eranga" <km***@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.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"InternetSearch" how can I do it on C#?
for any help, thanks in advance.
*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #2

P: n/a

"Eranga" <km***@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.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"InternetSearch" 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.com/downloads/details.aspx?FamilyID=890cd06b-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.
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.