Reputation: 23
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;
reg.OpenSubKey("SOFTWARE\\Microsoft\\Cryptography");
reg.DeleteValue("MachineGuid");
reg.Close();
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....
Upvotes: 0
Views: 2903
Reputation: 42443
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
{
key.DeleteValue("MachineGuid");
}
The RegistryKey
object implements IDisposable
, better apply the using pattern in that case to close and dispose the key.
Upvotes: 1