CursedSheep
CursedSheep

Reputation: 138

C# registry Can't delete MachineGuid access denied

Here's my code:

RegistryKey reg = Registry.LocalMachine;
var HKLM = reg.OpenSubKey(@"Software\\Microsoft\\Cryptography");
HKLM.DeleteValue("MachineGuid");

Problem: Even when I run it as an administrator; it will just give me an error that saying:

Cannot write to the registry key.

I can't delete anything in the local machine folder.

edit: I fixed it by unchecking "Prefer 32bit". or by checking if process is a 32 or 64bit application.

Upvotes: 1

Views: 1007

Answers (1)

user5158149
user5158149

Reputation:

You need to specify the RegistryKey to be writable if you want the write access.

Registry.LocalMachine.OpenSubKey(@"Software\\Microsoft\\Cryptography",true);

Upvotes: 2

Related Questions