Installing Plug-in by c#, error when write to registry

I registering my Plug-in followed This Web page, but after running the code, the program throws an error message:
Requested registry access is not allowed.

RegistryKey localMachine64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
            RegistryKey registryKey = localMachine64.OpenSubKey(@"SOFTWARE\McNeel\Rhinoceros\7.0\Plug-ins\4a5af943-0ee7-43aa-92f2-94fa5be8de8f", true);
            if (registryKey == null)
                RegistryKey software = localMachine64.OpenSubKey(@"SOFTWARE\McNeel\Rhinoceros\7.0\Plug-ins", true);
                if (software != null)
                    RegistryKey aimdir = software.CreateSubKey("4a5af943-0ee7-43aa-92f2-94fa5be8de8f");
                    aimdir.SetValue("Name", "MYTEST", RegistryValueKind.String);
                    aimdir.SetValue("FileName", patch, RegistryValueKind.String);

If install by rhino, that is ok when write to registry, who can give me some ideas ?

Hi @pythonuser,

What is running the above code?

In order to write to HKEY_LOCAL_MACHINE, the process doing the writing will need to be run with elevated privileges (e.g. Run as administrator).

If Rhino is not running as administrator, it just writes to HKEY_CURRENT_USER.

– Dale

@dale, thank you.