Cene Jenko Cene Jenko - 1 year ago 229
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....

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download