Under what account is a Rhino plugin running?

I think I have trouble reading and writing a registry value due to permissions on the key, but I’ve tried giving the everyone account full control and I still have the problem.

        RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\MyCompany\\MyPlugin", true);

The key exists and the spellings are all correct, but when the previous code runs, rk is null.

You shouldn’t have any issue reading from HKEY_LOCAL_MACHINE unless the key you don’t have permissions to read from the key.

For example, this should work:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  string owner = "<none>";
  string organization = "<none>";

  var sep = Path.DirectorySeparatorChar;
  var subkey = "SOFTWARE" + sep + "Microsoft" + sep + "Windows NT" + sep + "CurrentVersion";
  var key = Registry.LocalMachine.OpenSubKey(subkey);
  if (null != key)
    owner = (string) key.GetValue("RegisteredOwner");
    organization = (string) key.GetValue("RegisteredOrganization");

  RhinoApp.WriteLine("RegisteredOwner:  " + owner);
  RhinoApp.WriteLine("RegisteredOrganization:  " + organization);
  return Result.Success;

Writing to HKEY_LOCAL_MACHINE, on the other hand, is a little more difficult. The user will need to be logged in with an account that has local administrative privileges. Or, Rhino will need to be run “as administrator”, or with elevated privledges.

I’m a little confused, Dale. you give an example that reads a subkey of HKLM and then follow it by saying that writing to HKLM is a little more difficult.

By that, do you mean writing to the root HKLM?

In my code, my call to .OpenSubKey returns null, so the code that gets the values would never run.

I should also point out that the line of code I provided was running in the project from which I plucked it right up until my W8 machine went south and I had to rebuild it from the ground up. That’s why I wasn’t suspicious of my code, but rather wondering if my plugin was running under my own credentials or some mysterious profile about which I know nothing.

Is it more common (easier) to write to HKCU?

I don’t recall using the word “root.”

In general, plug-ins should read and write user setting to HKCU, HKLM is for setting that need to be shared by all users on the computer.

Also, Rhino plug-ins and command can read and write setting from and to the Registry for you using our Settings feature. Here is an example of a command that uses Settings.


Sorry, Dale, you didn’t use the word “root”, I did to try to get at the meaning of your last comment and I think you confirmed my contention.

I tried your code in a new plugin project and it worked fine. When I substituted my organization name and plugin name for Microsoft and Windows NT, key was null after the call to OpenSubKey.

It looks like I’ll need to dig more deeply into registry/permission problems.