cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
vijaykumbhani
Level 3

Basic MSI Project - Custom Action - unable to get installed path

Hi,

I am using InstallShiled 2014 Pro.
I have created Basic MSI Project.
Added CustomAction in Basic MSI Project. ( Call a function in a Windows Installer dynamic-link library )

PFA: Screenshot for more info
https://i.imgsafe.org/1b4b0f3066.png

Added the new property in property manager.

Name - CustomActionData
Value - [INSTALLDIR]bin

When I executed setup.exe then "Install" custom action has thrown.
I am unable to get installed path.

shared custom action dll source code.
[CODE]
UINT __stdcall Install( MSIHANDLE hInstall )
{
TCHAR customData[MAX_FILE_PATH * 3];

DWORD len = sizeof( customData ) / sizeof( TCHAR );

UINT gp = ::MsiGetProperty( hInstall,
_T("CustomActionData"),
customData,
&len);
::MessageBox(NULL, customData, "Install", MB_OK);
if (gp != ERROR_SUCCESS)
{
return ERROR_INSTALL_FAILURE;
::OutputDebugString("gp != ERROR_SUCCESS");
}

return ERROR_SUCCESS;
}
[/CODE]



I got "[INSTALLDIR]bin" instead of "installed path" value in the message.box.
Labels (1)
0 Kudos
(6) Replies
chad_petersen
Level 9

It's been a long time since I used C++ for a Custom Action. I always use C# these days. But see if this information helps

https://social.msdn.microsoft.com/Forums/windows/en-US/93ff80f2-3968-4a69-a123-e0bf079052f5/how-to-get-installdir-with-msi-and-custom-action-dll?forum=winformssetup

The passing of [TARGETDIR] into CustomActionData seems to have been the trick in this case.

I hope that helps.

Chad
0 Kudos
hidenori
Level 17

To pass a value as CustomActionData, you need to set a property that matches the name of the custom action. In your case, set the value of the property named CustomActions to [INSTALLDIR]bin.
0 Kudos
vijaykumbhani
Level 3

Hi chad.petersen

Thanks for reply

Please addressed my following steps.

1.
I have added a custom action in merge module.
PFA: screenshot has more info.
https://i.imgsafe.org/afb61dba52.png

2.
I have added Property in Property Manager in merge module.
PFA Screenshot for more info.
https://i.imgsafe.org/afd2ad7396.png

3.
I have added merge module in basic MSI Project.

4.
I have added the custom action from merge module in basic MSI project.
PFA: screenshot for more info.
https://i.imgsafe.org/afdda9c8e0.png


I have shared sample source code of dll
[CODE]
UINT __stdcall Install( MSIHANDLE hInstall )
{
TCHAR customData[MAX_FILE_PATH * 3];

DWORD len = sizeof( customData ) / sizeof( TCHAR );

UINT gp = ::MsiGetProperty( hInstall,
_T("CustomActionsForInstall"),
customData,
&len);
::MessageBox(NULL, customData, "Install", MB_OK);
if (gp != ERROR_SUCCESS)
{
return ERROR_INSTALL_FAILURE;
::OutputDebugString("gp != ERROR_SUCCESS");
}

return ERROR_SUCCESS;
}[/CODE]



I have set CustomActionName = PropertyName in merge module.

Please verify my install sequences of custom action.


I have set all property as per your instruction but it is not working now.

Regards,
Vijay Kumbhani
0 Kudos
hidenori
Level 17

The value of the property that matches the name of your custom action is available in the CustomActionData property within the deferred, commit, or rollback custom action. You need to get the value of the the CustomActionData property as your original code did:

[CODE]UINT __stdcall Install( MSIHANDLE hInstall )
{
TCHAR customData[MAX_FILE_PATH * 3];

DWORD len = sizeof( customData ) / sizeof( TCHAR );

UINT gp = ::MsiGetProperty( hInstall,
_T("CustomActionData"),
customData,
&len);
::MessageBox(NULL, customData, "Install", MB_OK);
if (gp != ERROR_SUCCESS)
{
return ERROR_INSTALL_FAILURE;
::OutputDebugString("gp != ERROR_SUCCESS");
}

return ERROR_SUCCESS;
}[/CODE]
0 Kudos
vijaykumbhani
Level 3

Hi Hidenori Yamanishi,

please explain what is/are the meaning of commit & rollback in "In-script execution" in the custom action.

I also tried with deferred and immediate execution in "In-script execution" in the custom action but it unable to get installed path.

You said to me in the previous reply. (01-25-2017, 08:36 AM - Post Number - #3 )
CustomAction Name and Property key both are same.
I had applied to set same of CustomAction Name and Property key.
Example:
CustomActionName: "CustomActionForInstall"
PropertyKey = "CustomActionForInstall".

I also changed MSI DLL code.
[CODE]UINT __stdcall Install( MSIHANDLE hInstall )
{
TCHAR customData[MAX_FILE_PATH * 3];

DWORD len = sizeof( customData ) / sizeof( TCHAR );

UINT gp = ::MsiGetProperty( hInstall,
_T("CustomActionsForInstall"),
customData,
&len);
::MessageBox(NULL, customData, "Install", MB_OK);
if (gp != ERROR_SUCCESS)
{
return ERROR_INSTALL_FAILURE;
::OutputDebugString("gp != ERROR_SUCCESS");
}

return ERROR_SUCCESS;
}[/CODE]

Please read my (01-27-2017, 01:35 PM Post Number - #4) and tell me
what is/are wrong?
0 Kudos
hidenori
Level 17

Deferred, commit, and rollback custom actions in Basic MSI and InstallScript MSI installations have access to only some of the built-in Windows Installer properties: CustomActionData, ProductCode, and UserSID. If you want a custom action to access any other properties during deferred, commit, or rollback execution, you can pass them as CustomActionData. You can do so by scheduling an immediate set-a-property type of custom action to set a property that matches the name of the custom action. The value of this property is then available in the CustomActionData property within the deferred, commit, or rollback custom action.
0 Kudos