Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Authorization to write registry to HKEY_CLASSES_ROOT

Discussion in 'Testing & Automation' started by y-iwata_asobism, Jun 14, 2022.

  1. y-iwata_asobism

    y-iwata_asobism

    Joined:
    Jun 2, 2022
    Posts:
    1
    Authorization to write registry to HKEY_CLASSES_ROOT
    ■Situation

    I don't know how to authorize HKEY_CLASSES_ROOT to write the registry. I did some research and created an "application manifest file" and created an executable file, but I get an error (UnauthorizedAccessException) that I do not have permission. The manifest file is placed in the \Assets\Mainfest. If I create an exe and start it with administrator privileges, I can write to it. The manifest permission write is not working? What is wrong with this, I would appreciate it if you could tell me as I have no knowledge at all.

    ■Creation code
    Code (CSharp):
    1. private static void AddRegistryTEST()
    2.         {
    3.             using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(@"TEST", true))
    4.             {
    5.                 if (key != null)
    6.                 {
    7.                     //REG_SZ Writing
    8.                     key.SetValue("TEST", Microsoft.Win32.RegistryValueKind.String);
    9.                     key.Close();
    10.                 }
    11.                 else
    12.                 {
    13.                     Debug.LogError("Error");
    14.                 }
    15.             }
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,533
    Why do you want to write to the registry? Perhaps there are easier alternatives, like Json files under AppData.

    Does it have to be HK class root? I vaguely remember that, like with folders, certain paths in the registry are more restricted than others. Perhaps you‘d rather write to HK current user instead.

    I also doubt that the manifest location under /Assets is correct. Unless you have some scripts or plugin that expects it there.