Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open registry key using full string path

Tags:

c#

.net

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?

like image 484
nosbor Avatar asked Oct 26 '13 09:10

nosbor


1 Answers

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.

like image 166
David Heffernan Avatar answered Sep 18 '22 14:09

David Heffernan