Windows installer, access a custom property inside a custom action in C++

Jeremy Sorensen

I have a C++ application in Visual Studio 2010 and I have a Windows Installer (i.e. setup project) to install it. I want to be able to invoke the installer like this:

Setup1.msi MYPROPERTY=MyValue

And then be able to extract the value "MyValue" from the property from within my custom action. I tried to get it working by following this tutorial(C++ custom actions) and this tutorial (passing arguments to custom actions, but in C#) combined with some MSDN searches to get this code:

#define WINDOWS_LEAN_AND_MEAN
#include <Windows.h>
#include <msi.h>
#include <msiquery.h>
#include <stdio.h>

BOOL APIENTRY DllMain(HANDLE, DWORD, LPVOID) {
    return TRUE;
}

UINT APIENTRY InstallCustomAction(MSIHANDLE install_handle) {
    static const wchar_t* kPropertyName = L"MYPROPERTY";

    //auto msi_handle = MsiGetActiveDatabase(install_handle);

    DWORD n = 0;
    //auto result = MsiGetProperty(msi_handle, kPropertyName, L"", &n);
    auto result = MsiGetProperty(install_handle, kPropertyName, L"", &n);
    wchar_t* value = nullptr;
    if (result == ERROR_MORE_DATA) {
        ++n;
        value = new wchar_t[n];
        //result = MsiGetProperty(msi_handle, kPropertyName, value, &n);
        result = MsiGetProperty(install_handle, kPropertyName, value, &n);
    }

    if (result == ERROR_SUCCESS) {
        wchar_t buffer[128];
        swprintf_s(buffer, L"n = %d, value = %s", n, value);
        MessageBox(nullptr, buffer, L"CustomAction", MB_OK);

    } else {
        MessageBox(nullptr, L"Error reading property", L"Error", MB_OK);
    }
    delete value;
    //MsiCloseHandle(msi_handle);
    return ERROR_SUCCESS;
}

I'm following the C# tutorial exactly in terms of the IDE (I have Entry Point set to InstallCustomAction and Custom Action Data set to /MYPROPERTY=[MYPROPERTY]) The custom action fires correctly but I don't get the parameter.

With the code as-is, I get n=0. If I use the msi_handle from MsiGetActiveDatabase I get an error (i.e. MsiGetProperty returns something other than ErrorSuccess).

How can I get the property that the user passes in on the command line from within my custom action?

Christopher Painter

There's no need to call MsiGetActiveDatabase. From what you've written it sounds like your custom action is scheduled for deferred execution. In that scenario you should be trying to get the property named "CustomActionData".

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Windows Installer custom actions: commit action won't get executed

From Dev

Installer does not close after running custom action

From Dev

Custom UIView variable / property Access

From Dev

IQueryable GET action / custom navigation property in ODataController

From Dev

Wix: Can't set a property with a custom action

From Dev

How to add really long hexadecimal registry in custom action in wix installer?

From Dev

Wix installer major upgrade custom action before removing old version

From Dev

Elevated installer with elevated custom action does not elevate executable

From Dev

Action not working with rendered property set on custom control, containing the action button

From Dev

Custom Action dll is not working . Installer is showing error: Wizard ended prematurely

From Dev

Accessing a wix property value inside a deferred .net custom action

From Dev

UIButton action not called inside custom view

From Dev

how to Invoke .exe file attached inside Advanced installer Prerequisite C# custom action

From Dev

Web API Access Route Template inside Custom Action Filter

From Dev

Spring @Value property is null inside of custom pojo

From Dev

Installer Custom Action Error - Type Mismatch: [string: "C:\"]

From Dev

How to evaluate a FacesComponent property inside a custom component

From Dev

UIButton target action inside custom class

From Dev

How to add really long hexadecimal registry in custom action in wix installer?

From Dev

Custom Action for Wix Installer failing after first time run

From Dev

Elevated installer with elevated custom action does not elevate executable

From Dev

Windows Universal App 8.1 C++ / Custom Class Property

From Dev

Why is my Wix Custom Action is breaking my installer

From Dev

Get enum type inside custom property attribute

From Dev

WIndows Installer Putting shortcuts into a custom folder with a property

From Dev

Is it possible to set property in Deferred custom action in WiX?

From Dev

Why can't I access to a UserControl custom property inside a Repeater?

From Dev

Custom Attribute on property in C#

From Dev

Custom property inside Web API Controller

Related Related

  1. 1

    Windows Installer custom actions: commit action won't get executed

  2. 2

    Installer does not close after running custom action

  3. 3

    Custom UIView variable / property Access

  4. 4

    IQueryable GET action / custom navigation property in ODataController

  5. 5

    Wix: Can't set a property with a custom action

  6. 6

    How to add really long hexadecimal registry in custom action in wix installer?

  7. 7

    Wix installer major upgrade custom action before removing old version

  8. 8

    Elevated installer with elevated custom action does not elevate executable

  9. 9

    Action not working with rendered property set on custom control, containing the action button

  10. 10

    Custom Action dll is not working . Installer is showing error: Wizard ended prematurely

  11. 11

    Accessing a wix property value inside a deferred .net custom action

  12. 12

    UIButton action not called inside custom view

  13. 13

    how to Invoke .exe file attached inside Advanced installer Prerequisite C# custom action

  14. 14

    Web API Access Route Template inside Custom Action Filter

  15. 15

    Spring @Value property is null inside of custom pojo

  16. 16

    Installer Custom Action Error - Type Mismatch: [string: "C:\"]

  17. 17

    How to evaluate a FacesComponent property inside a custom component

  18. 18

    UIButton target action inside custom class

  19. 19

    How to add really long hexadecimal registry in custom action in wix installer?

  20. 20

    Custom Action for Wix Installer failing after first time run

  21. 21

    Elevated installer with elevated custom action does not elevate executable

  22. 22

    Windows Universal App 8.1 C++ / Custom Class Property

  23. 23

    Why is my Wix Custom Action is breaking my installer

  24. 24

    Get enum type inside custom property attribute

  25. 25

    WIndows Installer Putting shortcuts into a custom folder with a property

  26. 26

    Is it possible to set property in Deferred custom action in WiX?

  27. 27

    Why can't I access to a UserControl custom property inside a Repeater?

  28. 28

    Custom Attribute on property in C#

  29. 29

    Custom property inside Web API Controller

HotTag

Archive