简体   繁体   中英

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;
            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....

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM