Re: get RegistryKey's parent? by Arthur
Arthur
Tue Sep 27 10:15:00 CDT 2005
Hi, thanks for the reminder about config files.
Its funny, I usually write ASP.NET app, and
am really writing my first significant Win app
since moving to the .NET platform.
I use .configs all the time in ASP, but completely
forgot about them for Windows.
Thanks for the "duh" reminder!
"Tiberiu Covaci" <tibi@ekoturdata.se> wrote in message
news:e3ZVkHzwFHA.2656@TK2MSFTNGP09.phx.gbl...
> Hi Arthur,
>
> Beside LocalMachine you, have several other members in the
> Microsoft.Win32.Registry class, which will help you solve your problem...
> If you are considering creating a new application, I advice you though not
> to use registry, but configuration files, as registry is considered
> "obsolete", and only Win32 has it, and will make your application NOT
> "platform independent", even though the only platform that .NET is
> available for is Win32.
>
> Tibi
>
>
> "Arthur Dent" <hitchhikersguideto-news@yahoo.com> wrote in message
> news:O1R729vwFHA.3856@tk2msftngp13.phx.gbl...
>>I think i just sent an empty reply ... apologies.
>>
>> Thanks for the ideas and info.
>>
>> That would only work for HKLM though, no?
>> The app data info is under HKCU, and it would
>> definitely be preferable to have something that is
>> not tied to any particular hive.
>>
>> I think i should be able to work out something
>> for my immediate needs though along these lines.
>>
>> Thanks.
>>
>> "Nick Hertl" <nhertl@gmail.com> wrote in message
>> news:1127781925.690450.47900@z14g2000cwz.googlegroups.com...
>>> I'm not sure if this is exposed by the Win32 APIs even, but here is a
>>> little C# app that does it for you:
>>>
>>> using System;
>>> using Microsoft.Win32;
>>>
>>> class MainClass
>>> {
>>> public static void Main()
>>> {
>>> string mainkeyname = @"SOFTWARE\Microsoft";
>>> RegistryKey rk = Registry.LocalMachine.OpenSubKey(mainkeyname);
>>> if(rk != null)
>>> {
>>> try
>>> {
>>> RegistryKey parent = GetParent(rk);
>>> try
>>> {
>>> Console.WriteLine("Got it: {0}", parent.Name);
>>> // do stuff here
>>> }
>>> finally
>>> {
>>> parent.Close();
>>> }
>>> }
>>> finally
>>> {
>>> rk.Close();
>>> }
>>> }
>>> }
>>>
>>> private static RegistryKey GetParent(RegistryKey value)
>>> {
>>> int first = value.Name.IndexOf(@"\");
>>> int last = value.Name.LastIndexOf(@"\");
>>> string parentname = value.Name.Substring(first+1, last-first);
>>> RegistryKey parent = Registry.LocalMachine.OpenSubKey(parentname);
>>> if(parent != null)
>>> {
>>> return parent;
>>> }
>>> return null;
>>> }
>>> }
>>>
>>
>>
>
>