There is something like Environment.SpecialFolder, but for registry paths

I want to keep some information about the application in the registry, and I'm not sure where to store it. I want the information to be for all users, so I would not use HKEY_CURRENT_USER. Maybe HKEY_LOCAL_MACHINE, but then I'm not sure where it is. I do not know what standards are for this and something like Environment.SpecialFolder , but for registry paths or folders it would be much safer and more elegant.

+4
source share
2 answers

No - unlike the file system, there is no need for such a method, because the registry has several standardized places where everything goes.

You must store your data in a key that follows in this format:

HKEY_HIVE\SOFTWARE\Publisher\Program

eg:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows

If you want the data to be global for the whole machine, put your things in HKEY_LOCAL_MACHINE , but note that you need administrator rights to write to this place, unless you change the DACL on your key to behave differently (in that or some other form of installer or something like that).

If you save data for each user (a hint is the majority of data per user), you should put things in HKEY_CURRENT_USER , which has the advantage that no special rights are required for this user to access their hive (by default).

+5
source

Check out the Microsoft.Win32.Registry object. There you can find some objects representing common registry paths, such as:

  • Currentuser
  • Localmachine
  • Classesoot
  • Users
  • PerformanceData li>
  • Currentconfig
  • DynData li>

For example, if you want to access HKEY_CURRENT_USER:

 Microsoft.Win32.RegistryKey key; key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Names"); key.SetValue("Name", "Isabella"); key.Close(); 
+7
source

Source: https://habr.com/ru/post/1334251/


All Articles