Write access to the HKLM portion of the registry usually requires that a process is running with elevated privileges (as Administrator). By passing "true" to OpenSubkey the sample code is requesting write access.
How to get past SecurityException accessing Registry?
In the Microsoft documentation for System.Console (https://learn.microsoft.com/en-us/dotnet/api/system.console?view=net-5.0#examples) there is an example related to "font linking". One part of that example is shown in the code snippet
RegistryKey key =
Registry.LocalMachine.OpenSubKey
(@"Software\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink",
true);
However, when I run the example, I get a SecurityException as shown below:
How do I give myself permission to access the Registry from a C# program?
Developer technologies | C#
3 answers
Sort by: Most helpful
-
-
RLWA32 49,541 Reputation points
2021-01-18T22:07:35.993+00:00 If you don't want to right-click and select "run as Administrator" then you can manifest your application to "requireAdministrator".
-
Karen Payne MVP 35,586 Reputation points Volunteer Moderator
2021-01-18T22:22:04.35+00:00 Have you tried adding a manifest file and work with the following by uncommenting.