2011-06-27 76 views
2

我有一个使用VS2010部署项目部署的Windows服务。我要求在安装程序中输入用户名/密码,然后将这些详细信息提交给注册中心以供使用的服务。从Visual Studio 2010部署项目写入HKLM

安装程序工作正常,自定义操作设置正确。如果我尝试转向HKLM,那么我不会收到任何错误,但是也没有输出,对HKCU的相同命令也可以正常工作。这与标准和管理用户(包括RunAs)相同。

public override void Install(IDictionary stateSaver) 
{ 
    base.Install(stateSaver); 

    var username = Context.Parameters["username"]; 
    var password = Context.Parameters["password"]; 

    // HKLM\Software\MySoftware 
    RegistryKey hklm = Registry.LocalMachine.CreateSubKey("SOFTWARE\\MySoftware"); 
    hklm.SetValue("username", username, RegistryValueKind.String); 
    hklm.SetValue("password", password, RegistryValueKind.String); 
    hklm.Close(); 

    // HKCU\Software\MySoftware 
    RegistryKey hkcu = Registry.CurrentUser.CreateSubKey("SOFTWARE\\MySoftware"); 
    hkcu.SetValue("username", username, RegistryValueKind.String); 
    hkcu.SetValue("password", password, RegistryValueKind.String); 
    hkcu.Close(); 
} 

我试过使用.OpenSubkey(x,true)而不是CreateSubkey(x)。结果是一样的。

任何帮助将大大appriciated。

问候

克里斯

+0

可能的重复:http://stackoverflow.com/questions/1782492/installer-custom-action-problem-cant-write-to-register-key – Blazes

+0

我无法在CustomAction上找到很好的参考,所以我无法验证,但也许你没有在CustomAction的'Install'部分中提升权限?您是否尝试将该代码移至“提交”。 – Blazes

+0

只要提交了一个尝试和相同的结果!现在已经将代码移到了控制台应用程序中,并且使用管理凭证显式运行并且没有运气。我没有看到任何理由,为什么我的HKLM安全设置将是股票以外的其他任何东西! – Chris

回答

4

在64位操作系统上,你会发现这些按键回HKLM \ SOFTWARE \ Wow6432Node \ MySoftware。这些注册表项已针对32位程序进行虚拟化。

+0

现货! Ta为解释! – Chris

相关问题