[wix-users] Custom Action firing

Habib Salim habib at hsalim.com
Tue Oct 17 06:47:01 PDT 2017


Good Morning.

 

I have a custom action in my installer that prompts the user to select an
image file - a logo that will be used by the application.

The path to the image file is then stored in the application.config file.

(relavant code pasted below)

 

This works when I run the installer but it also runs on uninstall
(although it does nothing)

It also runs whenever a new user open the application for the first time.

 

How do I ensure that this opens only on the first install?

 

Regards

Habib

    

    <Property Id="LOGO_PATH" Value="C:\" />

    <Binary Id="HSalimCo.WixGetLogoDLL"
SourceFile="$(var.TargetDir)WixGetLogo.CA.dll" />

    <CustomAction Id="CA_GetLogoPath"

                  BinaryKey="HSalimCo.WixGetLogoDLL"

                  DllEntry="OpenFileChooser"

                  Execute="immediate"

                  Return="check" />

 

    <InstallExecuteSequence>

      <Custom Action="CA_GetLogoPath" After="InstallInitialize" />

    </InstallExecuteSequence>

 

 

 

 

public class CustomActions

    {

        [CustomAction]

        public static ActionResult OpenFileChooser(Session session)

        {

            try

            {

                session.Log("Begin OpenFileChooser Custom Action");

                var task = new Thread(() => GetFile(session));

                task.SetApartmentState(ApartmentState.STA);

                task.Start();

                task.Join();

                session.Log("End OpenFileChooser Custom Action");

            }

            catch (Exception ex)

            {

                

                session.Log("Exception occurred as Message: {0}\r\n
StackTrace: {1}", ex.Message, ex.StackTrace);

                return ActionResult.Failure;

            }

            return ActionResult.Success;

        }

 

        private static void GetFile(Session session)

        {

            var fileDialog = new WinForms.OpenFileDialog {

                Filter = "Image Files (*.TIF, *.PNG,
*.JPG)|*.TIF;*.PNG;*.JPG|All files(*.*) | *.* "

                , Title = "Select your logo -this image will appear on
your reports" 

                

            };

            if (fileDialog.ShowDialog() == WinForms.DialogResult.OK)

            {

                session["LOGO_PATH"] = fileDialog.FileName;

            }

        }

    }



More information about the wix-users mailing list