Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a newbie in WiX and I have been struggling to build a WiX based installer for my winform c# application where I want to capture username and password during the installation and then save in app.config as well as encrypt the app.config file after post installation. I am successful in building the WixUI_mondo based dialogs for capturing the input as well as encrypting the app.config file. However I am facing problem while capturing the input and saving to app.config using custom actions. The code is given below. Please help me to resolve this as I am a newbie in WiX and the installer is urgent.

<pre lang="c#">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
using System.Configuration;
namespace CustomAction
{
public class CustomAction
{
    [CustomAction]
    public static ActionResult saveSales(Session session)
    {

        string salesPass = session["sales_pwd"];
        var fileMap = new ExeConfigurationFileMap();
        fileMap.ExeConfigFilename = "myApp.exe.config";
        var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
        config.AppSettings.Settings["salesPass"].Value =salesPass;
        config.Save(ConfigurationSaveMode.Modified);
        ConfigurationManager.RefreshSection("appSettings");
        return ActionResult.Success;
    }
    [CustomAction]
    public static ActionResult saveSuper(Session session)
    {
        string adminPass = session["admin_pwd"];
        var fileMap = new ExeConfigurationFileMap();
        fileMap.ExeConfigFilename = "myApp.exe.config";
        var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
        config.AppSettings.Settings["superPass"].Value = adminPass;
        config.Save(ConfigurationSaveMode.Modified);
        ConfigurationManager.RefreshSection("appSettings");
        return ActionResult.Success;
    }
}
}




and in the product.wsx file:


HTML
<InstallExecuteSequence>
  <Custom Action='saveSales' After='InstallFinalize'>NOT Installed</Custom>
  <Custom Action='saveSuper' After='saveSales'>NOT Installed</Custom>

</InstallExecuteSequence>

<Binary Id="CustomAction.dll" SourceFile="$(var.caPath)\CustomAction.CA.dll" />
<CustomAction Id="saveSales" BinaryKey="CustomAction.dll"
  DllEntry="saveSales" Execute="immediate" />
<CustomAction Id="saveSuper" BinaryKey="CustomAction.dll"
  DllEntry="saveSuper" Execute="immediate" />



when I commented out the following the following lines then the installer runs properly. any idea??
C#
config.AppSettings.Settings["superPass"].Value = adminPass; config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings");



Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900