chantivlad
Posts: 7
Joined: Tue Mar 18, 2008 2:11 pm

Custom Action EXE fails

Hi,

I am facing a problem for which I haven't found any solutions on the forum.

I have my own Dialog in User Interface -> Dialogs after the WelcomeDlg.

It is a simple Dialog with a Text Edit so that the user can type in the IPv4 adress of a machine or its name (e.g. "192.168.133.120" or "pcname"). The value is stored in HOSTNAMEDIT_PROPERTY.


When the use clicks on the "Next Button", I want to test if the name that the user entered is valid, that is if I can 'ping' the machine.
For that purpose, I use a "Published Events" on the "Next" button.
Its type is "DoAction", ist Argument is "myping.exe" and ist condition is "AI_INSTALL".

"myping.exe" is an executable that I built that returns 0 in the case of successful ping, and various other return values >= 0 otherwise. It is defined as follow in "Project Details" -> "Custom Actions" -> "UI Custom Actions".
The "Executions Properties" is "Synchronous execution, check return code".

I would thus expect the return value of this custom action to be the same of that of my "myping.exe".

However, when I build and run ("Run and Log")the installer, I get following error message :

Action 21:23:41: NewDialog. Dialog created
MSI (c) (F0:98) [21:23:47:730]: PROPERTY CHANGE: Modifying HOSTNAMEDIT_PROPERTY property. Its current value is '192.168.133.203'. Its new value: 'test string'.
MSI (c) (F0:98) [21:23:47:792]: Doing action: myping.exe
Action 21:23:47: myping.exe.
Action start 21:23:47: myping.exe.
MSI (c) (F0:98) [21:23:47:886]: Note: 1: 1722 2: myping.exe 3: E:\via488\tmp\MSI1CC3.tmp 4: test string

Do you know how I could solve this problem ?
Thank you in advance for your help,

Florent
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi Florent,

Does your custom action support two string parameters ore only one? If it supports only one parameter then you need to enclose in quotes (") the property used in the command line of the custom action. This is because the test string command line will launch the EXE like this:

Code: Select all

myping.exe test string
(with two different parameters). If your EXE supports only one string parameter then the correct command line is this:

Code: Select all

myping.exe "test string"
This way the two words are considered as one string parameter.

Let me know if the problem persists when using quotation marks in the command line. The command line should look like this:

Code: Select all

"[HOSTNAMEDIT_PROPERTY]"
Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
chantivlad
Posts: 7
Joined: Tue Mar 18, 2008 2:11 pm

Hi Cosmin,

thank you for your answer.

Yes, my program takes care of the case argc > 2.

I think the problem comes that if the ping fails, the installer will return a failure as stated in the docu : "Custom actions that are executable files must return a value of 0 for success. The installer interprets any other return value as failure."

So obviously a Custom Action is not suited for what I want to do.

Could you please tell me the best way to achieve something as simple as :
- ping the host name entred by the user
- retrieve the return value of the ping
- enable or disable the "Next" button depending on the return value of the ping, and possibly make a text appear for the user ("Failure" or "Success").

Thank you in advance,
Florent
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi Florent,

What you need to accomplish can be done only by using a custom action. Also, this custom action must return 0 in order to let Windows Installer know that the custom action was executed correctly.

I suggest another approach:
- create a C++ DLL custom Action which does the same this as the EXE
- this DLL will always return 0
- inside the DLL you can use the MsiSetProperty function to set the value of a public property depending on the value entered by the user
http://msdn2.microsoft.com/en-us/library/aa370391.aspx
- in the "Dialogs" page you use the property set by the custom action to let the user know that he entered an incorrect value

You can notify the user by using a Script Inline custom action scheduled in the "UI Custom Actions" sequence. This custom action will have the "Script Text" field set to something like this:

Code: Select all

MsgBox "The location you entered is incorrect"
Also, in order to make sure that the user cannot go to the next dialog you can condition the "NewDialog" published control event for the "Next" button with the property set by the DLL custom action.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
chantivlad
Posts: 7
Joined: Tue Mar 18, 2008 2:11 pm

Hi Cosmin and happy Easter,

I followed your instructions, but I still am not successful.

I built my exe as a DLL exporting main(argc, argv) in which I do a :

Code: Select all

 MsiSetProperty(*hProduct,
                                 _T("MyPingedHostNameProperty"),
                                 _T("Success"));
if the ping succeeded, and

Code: Select all

MsiSetProperty(*hProduct,
                                 _T("MyPingedHostNameProperty"),
                                 _T("Failure"));
if the ping fails.

Now in the "Init Events" of my dialog, I want to call the "main(argc,argv)" function of my DLL with HOSTNAMEDIT_PROPERTY as an argument.

My "Custom Action" for that purpose looks like following :

Code: Select all

Source Path: E:\path\to\my\ping.dll

Code: Select all

Source Type: Dynamic linked library (*.dll)

Code: Select all

Function Name: main [HOSTNAMEDIT_PROPERTY]

Code: Select all

Execute Properties: Synchronous Execution, check return code

Code: Select all

Execute Options: Immediate Execution.

Code: Select all

Scheduling Options: Alway Execute.
When I "Build and Run" and when the DLL is called, I get an error message saying the "DLL required for this install to complete could not be run."

Am I missing something ?

Thank you in advance,
Florent
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

The first problem is that you are trying to pass HOSTNAMEDIT_PROPERTY in the "Function Name" field. Note that in this field you must specify only the name of the function. If you need to pass parameters to the function you can use the Action Data field.

The second problem is that you are using the MsiSetProperty function incorrectly. Note that it sets an installer property, therefore you should use it to set HOSTNAMEDIT_PROPERTY, not MyPingedHostNameProperty.

Let me know if the problem persist after making the necessary modifications.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
chantivlad
Posts: 7
Joined: Tue Mar 18, 2008 2:11 pm

Hi,

The first problem is that you are trying to pass HOSTNAMEDIT_PROPERTY in the "Function Name" field. Note that in this field you must specify only the name of the function. If you need to pass parameters to the function you can use the Action Data field.
Well, the thing is, in "Custom Actions" --> "UI Cutsom Actions", there is no "Action Data" field.
The "Action Data" field is only available for "Custom Actions" --> "Install Execute Sequence".
And I want to execute the function called when the user clicked "Next" on the UI.
The second problem is that you are using the MsiSetProperty function incorrectly. Note that it sets an installer property, therefore you should use it to set HOSTNAMEDIT_PROPERTY, not MyPingedHostNameProperty.
OK, but then it does not work as wanted : HOSTNAMEDIT_PROPERTY should be the name of the computer to ping (tipped by the user in the edit field of the dialog), and not the result of the ping call in the DLL.

I thought I could simply set a MSI Property of the installer that does not exist yet. If it is not the case then do I have to overwrite my existing HOSTNAMEDIT_PROPERTY and lose the information it contains ?

Thank you,
Florent
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

In this case you can get the value of the HOSTNAMEDIT_PROPERTY inside your DLL by using the MsiGetProperty function:
http://msdn2.microsoft.com/en-us/library/aa370134.aspx

Also, in your custom action you can set another public property (the name of the property contains only uppercase letters) which will contain the result of the ping. Note that it is recommended to initialize this property with a default value in the "Install Parameters" page.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
chantivlad
Posts: 7
Joined: Tue Mar 18, 2008 2:11 pm

Hi,

according to:
http://msdn2.microsoft.com/en-us/librar ... S.85).aspx
only Windows installer is needed to call the function MsiOpenProduct.

I try to open the "MySetup.msi" file in my DLL "myping.dll" using

Code: Select all

MSIHANDLE* hProduct = NULL;
UINT val = MsiOpenProduct(_T("MySetup.msi"), hProduct);
if (testval != ERROR_SUCCESS)
{
        cerr << "Error (" << testval << ") opening product MySetup.msi." << endl;
        return res;
    }
I know this is more of a Microsoft-API-related question, but I always get an error 87 (ERROR_INVALID_PARAMETER) when calling this piece of code.
Have you heard of a similar problem ?

Thank you,
Florent
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

You don't need to use the MsiOpenProduct function because you can get the handle of the installation package by setting it as a parameter for the function you are using. This way, your function will get the handle automatically from the installation and you can use it in the MsiGetProperty or MsiSetProperty functions.

We have a sample DLL custom action, please take a look:
http://www.advancedinstaller.com/user-g ... n-dll.html

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ms_bhandari
Posts: 11
Joined: Mon Feb 25, 2008 8:31 pm
Location: VA

Re: Custom Action EXE fails

I have a simillar problem and hope to get response.

I have an existing EXE program written in vb6 which I want to run on 'Next' button click of a custom dialog box and based on the return value of that exe program - I want to continue or stop the installation.

Thanks.

Madhu
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Custom Action EXE fails

Hi Madhu,

Please note that an EXE custom action cannot set installer properties because it runs in a different process. However, since you want to stop the installation based on the return value, your custom action should have these return codes:
  • 0 will continue the installation
  • any other value will stop the installation
Note that a non-zero return value means that the custom action has failed. Therefore, an error will be shown to the user and the installation will be rolled back.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”