1
我在一个项目中有一个自定义的安装方法,我正在加载用于我的项目的用户许可证代码。代码如下所示:如何预先加载我的VS安装程序中的上下文参数?
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
string targetDirectory = Context.Parameters["targetdir"];
string licenseCode = Context.Parameters["liccode"];
string exePath = string.Format("{0}prog1.exe", targetDirectory);
Configuration config = ConfigurationManager.OpenExeConfiguration(exePath);
config.AppSettings.Settings["LicenseCode"].Value = licenseCode;
config.Save();
}
什么我运行中却是我的用户不得不经常重新输入他们的许可证代码到“文本框(A)”的用户界面对话框,我我补充说。所以我想要做的是读取存储值的注册表,并用存储值预填充安装程序屏幕。
所以这里是我的尝试,但这似乎并没有工作......也许是因为它没有在事件链中的正确点解雇。
protected override void OnBeforeInstall(IDictionary savedState)
{
RegistryKey key;
string baseKey = "SOFTWARE\\Test\\Prog1";
try
{
key = Registry.LocalMachine.OpenSubKey(baseKey, false);
Context.Parameters["liccode"] = key.GetValue("LicenseCode").ToString();
}
catch(Exception e)
{
}
base.OnBeforeInstall(savedState);
}
任何人都有如何解决这个问题的建议?
我不使用自定义操作,只是一个“文本框(A)”对话框来捕获他们的许可证代码。我发现我可以设置注册表搜索并查看属性,但是我没有看到使用该值预填充对话框的方法。那里有任何想法? – SeaSharp 2011-03-14 14:29:19
明白了,非常好。 – SeaSharp 2011-03-14 14:57:38
因此,我根据Christopher Painter的建议设置了注册表搜索。这样做,它给了我一个属性名称。然后在用户对话框“EDIT1VALUE”属性中,我将其设置为来自注册表搜索的[PROPERTYNAME]。瞧! – SeaSharp 2011-03-14 14:59:38