开发者

How can I pre-load a Context Parameter in my VS Installer?

I have a custom Install method in a project where I'm loading a user's license code for use in my project. The code looks like this:

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

What I'm running in to however is that my users are constantly having to re-key their license code in to the "Textboxes (A)" User Interface Dialog that I've added. So what I'd like to do is read the registry where the value is stored and pre-populate the installer screen with the stored value.

So here's what I tried, but this didn't seem to work ... maybe b开发者_Python百科ecause it's not fired at the right point in the chain of events.

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

Anyone have suggestions on how to approach this?


You can use a System Search ( AppSearch and RegLocator tables ) to pull the value into a property at the beginning of the install. You shouldn't need a custom action to do this.

BTW, VDPROJ and InstallUtil has some serious drawbacks. I would look into factoring most of your installer out into a WiX Merge module and replacing your InstallUtil with DTF ( assuming you can't eliminate all of your custom actions in the first place )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜