Before you try to answer this, do a Google Quick Search. I would like to note that I already. In this case, I have the following method that tries to change the registry key value. The problem I get is that when it does, it throws an UnauthorizedAccessException , although I opened the key as writable . I run Visual Studio as an administrator and even tried to make a small .exe with the manifest file, forcing it to run as an administrator, which would execute the code without any luck. The key already exists; it does not try to enter the CreateKey method. Here is the code block.
Path = "S-1-5-21-1644491937-1078145449-682003330-5490\Software\Microsoft\Windows\CurrentVersion\Policies\System" Key = "DisableTaskMgr" NewValue = 1 public OperationResult ModifyKey() { OperationResult result = new OperationResult(); if (!Path.IsNullOrEmptyTrim()) { if (!Key.IsNullOrEmptyTrim()) { try { var key = Microsoft.Win32.Registry.Users.OpenSubKey(Path, true); if (key != null) { key.SetValue(Key, NewValue); key.Close(); } else { result = CreateKey(); } } catch (Exception ex) { result.SetFail("Error accessing registry", ex); } } else { result.SetFail("Registry key was null"); } } else { result.SetFail("Registry path was null"); } return result; }
Do I need to manually navigate to the registry tree so that every OpenSubKey call is recorded? I tried this too, threw the same error anyway ...
c # registry unauthorizedaccessexcepti
Middas
source share