nosbor
nosbor

Reputation: 3009

Open registry key using full string path

Is there any chance to open registry key using full registry path like:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon?

I know that I can open that node using:

RegistryKey.OpenBaseKey(RegistryHive.LocalMachine).OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion\Winlogon")

But I would like to do it easier... In my application user can put registry key as a string and my application have to do somthing with it. Now I have to check what is on the begining and conditionally select suitable RegistryHieve. Isn't there any better and easier way for that?

Upvotes: 6

Views: 6446

Answers (1)

David Heffernan
David Heffernan

Reputation: 613572

You just have to write a function that parses the registry path. Split the path at the first separator and compare the part before the first separator against the known root keys. Then open the key using the code in your question.

Upvotes: 4

Related Questions