如何设置从我安装此注册表值 [英] How can I set this registry value from my installer

查看:157
本文介绍了如何设置从我安装此注册表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的的.msi 的安装包,我在写一个注册表值一个C#自定义操作:

  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run 



自定义操作被推迟,因为我需要提升的权限一些我试图安装密钥。



<$ P:但是,因为它被延迟,因为它是有提升的权限启动,所以我的注册表值实际上被写在这个动作写入系统帐户的当前用户$ p> HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Run

我怎样才能安装这个注册表值写入谁发动的安装包而不是系统帐户的注册表中的用户的注册表?


解决方案

  Microsoft.Win32.RegistryKey键; 
键= Microsoft.Win32.Registry.CurrentUser.CreateSubKey(名称);
key.SetValue(姓名,伊莎贝拉);
key.Close();



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



编辑:

 字符串strSID =; 
字符串username = System.Security.Principal.WindowsIdentity.GetCurrent()名称;
NTACCOUNT NTUSER =新NTACCOUNT(用户名);
的SecurityIdentifier SID =(的SecurityIdentifier)ntuser.Translate(typeof运算(的SecurityIdentifier));
strSID = sID.ToString();

Registry.Users.SetValue(SID + @\key,值);



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



您需要:

 使用系统。 Security.Principal; 



此代码。


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

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

The custom action is deferred because I need elevated privileges for some of the keys I am trying to install. However, because it is deferred, this action writes to the current user of the system account since it is launched with elevated permissions, so my registry value actually gets written in:

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

How can I get the installer to write this registry value into the registry of the user who launched the installation package instead of the system account's registry?

解决方案

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.

这篇关于如何设置从我安装此注册表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆