简体   繁体   English

从Visual Studio 2010部署项目写入HKLM

[英]Write to HKLM from Visual Studio 2010 deployment project

I have a windows service that is deployed using a VS2010 deployment project. 我有一个使用VS2010部署项目部署的Windows服务。 I require that a username/password be entered in the installer and then these details commited to the registry for the service to use. 我要求在安装程序中输入用户名/密码,然后将这些详细信息提交给注册表以供服务使用。

The installer works fine, and the custom actions are setup correctly. 安装程序工作正常,并且自定义操作已正确设置。 If i try to commt to HKLM i get no error but no output either, the same command to HKCU works fine. 如果我尝试通向HKLM,则不会出错但也不会输出,对HKCU的相同命令也可以正常工作。 This is the same as both a standard and administrative user (including RunAs). 这与标准用户和管理用户(包括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();
}

I have tried using .OpenSubkey(x, true) instead of CreateSubkey(x). 我尝试使用.OpenSubkey(x,true)而不是CreateSubkey(x)。 The results are the same. 结果是一样的。

Any help would be greatly appriciated. 任何帮助将不胜感激。

Regards 问候

Chris 克里斯

On a 64-bit operating system, you'll find these keys back in HKLM\\Software\\Wow6432Node\\MySoftware. 在64位操作系统上,您可以在HKLM \\ Software \\ Wow6432Node \\ MySoftware中找到这些密钥。 These registry keys are virtualized for 32-bit programs. 这些注册表项针对32位程序进行了虚拟化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM