473,465 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Iterate through registry sub keys.

I am trying to read values to the subkeys under HKLM\...\Uninstall.

I get to this point...

RegistryKey Sftw = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMa chine,
name).OpenSubKey("software").OpenSubKey("Microsoft ").OpenSubKey("Windows").OpenSubKey("CurrentVersio n").OpenSubKey("Uninstall");

foreach (string SubKey in Sftw.GetSubKeyNames())
{

}

and now I want to read some of the values to the subkeys. Nothing I have
tried works. All I have been able to accomplish is reading the name of the
subkey itself.

I feel I am missing something here...

Thanks for any assistance!
Nov 17 '05 #1
4 6641
James,

You say it doesn't work. Are you sure you have permission to access
those keys? Also, do you get an exception, or it doesn't return the value
that you think you should get?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James" <Ja***@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
I am trying to read values to the subkeys under HKLM\...\Uninstall.

I get to this point...

RegistryKey Sftw =
RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMa chine,
name).OpenSubKey("software").OpenSubKey("Microsoft ").OpenSubKey("Windows").OpenSubKey("CurrentVersio n").OpenSubKey("Uninstall");

foreach (string SubKey in Sftw.GetSubKeyNames())
{

}

and now I want to read some of the values to the subkeys. Nothing I have
tried works. All I have been able to accomplish is reading the name of
the
subkey itself.

I feel I am missing something here...

Thanks for any assistance!

Nov 17 '05 #2
I'm guessing I just don't know the method to read the subkeys. The only
value I have been able to figure out how to return is the name of the
subkeys... I did try this...

foreach (RegKey SubKey in Sftw.GetSubKeyNames())
{
Console.WriteLine(SubKey.GetValue("DisplayName").T oString());
}

and caught an error converting string to registrykey.

"Nicholas Paldino [.NET/C# MVP]" wrote:
James,

You say it doesn't work. Are you sure you have permission to access
those keys? Also, do you get an exception, or it doesn't return the value
that you think you should get?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James" <Ja***@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
I am trying to read values to the subkeys under HKLM\...\Uninstall.

I get to this point...

RegistryKey Sftw =
RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMa chine,
name).OpenSubKey("software").OpenSubKey("Microsoft ").OpenSubKey("Windows").OpenSubKey("CurrentVersio n").OpenSubKey("Uninstall");

foreach (string SubKey in Sftw.GetSubKeyNames())
{

}

and now I want to read some of the values to the subkeys. Nothing I have
tried works. All I have been able to accomplish is reading the name of
the
subkey itself.

I feel I am missing something here...

Thanks for any assistance!


Nov 17 '05 #3
James,

I see it now. You will have to open each sub key, you can't just cast
it to a registry key. You need to do this:

foreach (string subKeyName in Sftw.GetSubKeyNames())
{
// Open the key.
using (RegistryKey subKey = Sftw.OpenSubKey(subKeyName))
{
// Write the value.
Console.WriteLine(subKey.GetValue("DisplayValue"). ToString());
}
}
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James" <Ja***@discussions.microsoft.com> wrote in message
news:03**********************************@microsof t.com...
I'm guessing I just don't know the method to read the subkeys. The only
value I have been able to figure out how to return is the name of the
subkeys... I did try this...

foreach (RegKey SubKey in Sftw.GetSubKeyNames())
{
Console.WriteLine(SubKey.GetValue("DisplayName").T oString());
}

and caught an error converting string to registrykey.

"Nicholas Paldino [.NET/C# MVP]" wrote:
James,

You say it doesn't work. Are you sure you have permission to access
those keys? Also, do you get an exception, or it doesn't return the
value
that you think you should get?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James" <Ja***@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
>I am trying to read values to the subkeys under HKLM\...\Uninstall.
>
> I get to this point...
>
> RegistryKey Sftw =
> RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMa chine,
> name).OpenSubKey("software").OpenSubKey("Microsoft ").OpenSubKey("Windows").OpenSubKey("CurrentVersio n").OpenSubKey("Uninstall");
>
> foreach (string SubKey in Sftw.GetSubKeyNames())
> {
>
> }
>
> and now I want to read some of the values to the subkeys. Nothing I
> have
> tried works. All I have been able to accomplish is reading the name of
> the
> subkey itself.
>
> I feel I am missing something here...
>
> Thanks for any assistance!


Nov 17 '05 #4
That made the difference... I saw the keyword using in the MSDN examples I
just could not see how to apply it here. Thanks for your help!

"Nicholas Paldino [.NET/C# MVP]" wrote:
James,

I see it now. You will have to open each sub key, you can't just cast
it to a registry key. You need to do this:

foreach (string subKeyName in Sftw.GetSubKeyNames())
{
// Open the key.
using (RegistryKey subKey = Sftw.OpenSubKey(subKeyName))
{
// Write the value.
Console.WriteLine(subKey.GetValue("DisplayValue"). ToString());
}
}
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James" <Ja***@discussions.microsoft.com> wrote in message
news:03**********************************@microsof t.com...
I'm guessing I just don't know the method to read the subkeys. The only
value I have been able to figure out how to return is the name of the
subkeys... I did try this...

foreach (RegKey SubKey in Sftw.GetSubKeyNames())
{
Console.WriteLine(SubKey.GetValue("DisplayName").T oString());
}

and caught an error converting string to registrykey.

"Nicholas Paldino [.NET/C# MVP]" wrote:
James,

You say it doesn't work. Are you sure you have permission to access
those keys? Also, do you get an exception, or it doesn't return the
value
that you think you should get?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James" <Ja***@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
>I am trying to read values to the subkeys under HKLM\...\Uninstall.
>
> I get to this point...
>
> RegistryKey Sftw =
> RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMa chine,
> name).OpenSubKey("software").OpenSubKey("Microsoft ").OpenSubKey("Windows").OpenSubKey("CurrentVersio n").OpenSubKey("Uninstall");
>
> foreach (string SubKey in Sftw.GetSubKeyNames())
> {
>
> }
>
> and now I want to read some of the values to the subkeys. Nothing I
> have
> tried works. All I have been able to accomplish is reading the name of
> the
> subkey itself.
>
> I feel I am missing something here...
>
> Thanks for any assistance!


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: vbMark | last post by:
Hello, In regards to the Registry... Can someone give me an example of how to list an unknown number of subkeys under a key, and put the key names in one column of a listbox, and the key...
21
by: Kevin Swanson | last post by:
I'm attempting some remote registry manipulation via C#. I've written a test app to simply grab a specified key from a specified hive on a specified machine. The call to OpenSubKey is throwing...
0
by: Jigar Mehta | last post by:
Hye, any idea about iterating through registry keys??? how to do that... code snippet will help me a lot... -- Jigar Mehta jbmehtain@yahoo.co.in
4
by: Kevin L | last post by:
I store some application settings in the registry under HKEY_LOCAL_MACHINE\Software\MyApplication I want to allow full access to this key and subkeys. Currently, I manually change the...
9
by: Newbie Coder | last post by:
Hello Newsgroup Readers I would like to know how to go & do the following: I have a certain registry key that has sub values Example: Key1 http://www.microsoft.com Key2 ...
3
by: lazy | last post by:
I have a berkely db and Im using the bsddb module to access it. The Db is quite huge (anywhere from 2-30GB). I want to iterate over the keys serially. I tried using something basic like for key...
0
by: Gary | last post by:
I'm having trouble entering Additional Registry Keys into my Package Solution that will deploy the Access 2007 runtime. (Client machine is running XP with Office 2007 Standard.) The Package...
11
by: Unknown Hero | last post by:
Tim Golden wrote: The first link which points to the Python documentation for the _winreg module I already checked, even before coming here. I am wondering how I should do the loop I need (go...
12
by: =?Utf-8?B?YXVsZGg=?= | last post by:
i current have a way to read both local and remote machines registry keys and create a textual view (.txt output). i now looking for ways to do export of local and remote mahcine registry keys...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.