You need to remove the CustomAction attribute from the SHGetFolderPath
method and put it on your WriteFileToDisk method.

On Sun, Dec 7, 2014 at 6:06 AM, Sarvagya Pant <sarvagya.p...@gmail.com>
wrote:

> ​I have been making a MSI Installer that can get the value of property
> passed to it and write a Config file. I am supposed to call MSI as:
>
> msiexec /i myfile.msi /l*v output.txt IPADDRESS="192.168.1.1"
>
> and get value of IPADDRESS
>
> I have following Wix C# Code that is supposed to work​
>
> ​namespace SetupCA
> {
>
>     public class CustomActions
>     {
>
>         [CustomAction]
>         [DllImport("shell32.dll")]
>         public static extern Int32 SHGetFolderPath(
>             IntPtr hwndOwner,           // Handle to an owner window.
>             Int32 nFolder,              // A CSIDL value that identifies
> the folder whose path is to be retrieved.
>             IntPtr hToken,              // An access token that can be used
> to represent a particular user.
>             UInt32 dwFlags,             // Flags to specify which path is
> to be returned. It is used for cases where
>             // the folder associated with a CSIDL may be moved or renamed
> by the user.
>             StringBuilder pszPath);
>         public static ActionResult WriteFileToDisk(Session session)
>         {
>
>             session.Log("Begin WriteFileToDisk");
>
>             const int CSIDL_LOCAL_APPDATA = 0x001c;
>             StringBuilder path1 = new StringBuilder(256);
>             SHGetFolderPath(IntPtr.Zero, CSIDL_LOCAL_APPDATA, IntPtr.Zero,
> 0, path1);
>             session.Log("LOCAL APP_DATA PATH " + path1.ToString());
>
>             string ipAddress = session["IPADDRESS"];
>             string path = path1.Replace(@"\", @"\\").ToString();
>             path = path + @"\\lpa\\config\\";
>             session.Log("LOCAL APP_DATA PATH NOW MODIFIED " +
> path.ToString());
>             string temp = @"
> {{
>  ""logpoint_ip"" : ""{0}""
> }}";
>             string config = string.Format(temp, ipAddress);
>             session.Log("Config Generated was " + config);
>             System.IO.Directory.CreateDirectory(path);
>             try
>             {
>                 System.IO.File.Delete(path + "lpa.config");
>             }
>             catch (Exception e)
>             {
>                 session.Log(e.ToString());
>             }
>             System.IO.File.WriteAllText(path + "lpa.config", config);
>             session.Log("Ending WriteFileToDisk");
>
>             return ActionResult.Success;
>         }
>     }
> }​
>
> ​The above code is supposed to get the value of IPADDRESS and write a file
> to the folder given by CSIDL_LOCAL_APPDATA . For this I used
> SHGetFolderPath inside shell32.dll using DLLIMPORT.
>
> My Wix file is given below:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi";>
>     <Product Id="*" Name="CustomWixInstallerWithCustomAction"
> Language="1033" Version="1.0.0.0" Manufacturer="LogPoint"
> UpgradeCode="ba9015b9-027f-4451-adb2-e38f9168a850">
>         <Package InstallerVersion="200" Compressed="no"
> InstallScope="perMachine" />
>
>         <MajorUpgrade DowngradeErrorMessage="A newer version of
> [ProductName] is already installed." />
>         <MediaTemplate />
>
>         <Feature Id="ProductFeature"
> Title="CustomWixInstallerWithCustomAction" Level="1">
>             <ComponentGroupRef Id="ProductComponents" />
>         </Feature>
>     </Product>
>
>     <Fragment>
>         <Directory Id="TARGETDIR" Name="SourceDir">
>             <Directory Id="ProgramFilesFolder">
>                 <Directory Id="INSTALLFOLDER" Name="CustomWixInstaller" />
>             </Directory>
>         </Directory>
>     </Fragment>
>
>     <Fragment>
>         <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
>       <Component Id="SomeRandomEXE">
>         <File Source
> ="G:\SarVaGYa\myworkspace\LatestLpa\lpa\lpa_c\here\src\lpa\Release\lpa.exe"
> />
>       </Component>
>         </ComponentGroup>
>     <Binary Id="SetupCA"  SourceFile="G:\visual studio
> stuffs\SetupCA\SetupCA\bin\Release\SetupCA.CA.dll"/>
>     <CustomAction Id="WRITEFILETODISK" Execute="immediate"
> BinaryKey="SetupCA" DllEntry="WriteFileToDisk" />
>     <InstallExecuteSequence>
>       <Custom Action="WRITEFILETODISK" Sequence="2"></Custom>
>     </InstallExecuteSequence>
>     </Fragment>
> </Wix>
>
> Both get compiled but when I try to install the MSI using the command I
> wrote above I get the following error:
>
> "There is a problem with this Windows Installer package. A DLL required for
> this install to complete could not be run. "
>
> How do I solve this Issue? Can't I use DLLImport in Wix C# Custom Action.​
>
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
>
> http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
> _______________________________________________
> WiX-users mailing list
> WiX-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wix-users
>
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to