如何从我的安装程序中设置此registry值

在我的.msi安装程序包中,我有一个C#自定义操作,将registry值写入:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run 

自定义操作是推迟的,因为我需要提升一些我试图安装的密钥的权限。 但是,因为它被延迟,所以此操作将写入系统帐户的当前用户,因为它是以提升的权限启动的,所以我的registry值实际上被写入:

 HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Run 

如何让安装程序将此registry值写入启动安装软件包的用户的registry中而不是系统帐户的registry中?

 Microsoft.Win32.RegistryKey key; key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Names"); key.SetValue("Name", "Isabella"); key.Close(); 

你试试这个,这里从微软的参考

编辑:

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

试试这个,你应该读一下Registry.Users.SetValue

你需要:

 using System.Security.Principal; 

为此代码。