Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: install installer wix
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:
 

<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??
config.AppSettings.Settings["superPass"].Value = adminPass; config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings");
 

Posted 29-Feb-12 20:12pm

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

  Print Answers RSS
0 OriginalGriff 584
1 Maciej Los 275
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 1 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100