How can I set this registry value from my installer

后端 未结 1 1321
轻奢々
轻奢々 2021-01-25 00:16

In my .msi installer package, I have a C# custom action that writes a registry value in:

HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion         


        
相关标签:
1条回答
  • 2021-01-25 00:44
    Microsoft.Win32.RegistryKey key;
    key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Names");
    key.SetValue("Name", "Isabella");
    key.Close();
    

    Do you try this, here reference from microsoft

    Edit:

                string strSID = "";
                string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                NTAccount ntuser = new NTAccount(userName);
                SecurityIdentifier sID = (SecurityIdentifier)ntuser.Translate(typeof(SecurityIdentifier));
                strSID = sID.ToString();
    
                Registry.Users.SetValue(sID + @"\key", value);
    

    Try this, you should probably read about Registry.Users.SetValue

    You need:

    using System.Security.Principal;
    

    for this code.

    0 讨论(0)
提交回复
热议问题