view raw
Cene Jenko Cene Jenko - 6 months ago 67
C# Question

Change MachineGuid C#

i was wondering for a project of mine, is it possible to change the MachineGuid from the registry or any other way? I've seen it in multiple applications and I can't do it myself..This is my code

RegistryKey reg = Registry.LocalMachine;

consolebox.AppendText("MachineGuid should be changed!\n");

But it doesn't work.. it doesn't delete the MachineGuid value, which would automatically regenerate in about a second....

The error says that it doesnt find the value.. that MachineGuid doesn't exist... but when i go to regedit it does?

If i don't run the application as an Administrator, it says the value got deleted, but if i do it says it doesn't exist....


You have a couple of issues, first you don't open the key to be writeable and you don't use the result of OpenSubKey. That method returns the key you actually opened.

RegistryKey reg = Registry.LocalMachine;
using(var key = reg.OpenSubKey("SOFTWARE\\Microsoft\\Cryptography", true)) // writeable

RegistryKey implements IDisposable, better apply the using pattern in that case to close and dispose the key.