MGS
Posts: 83
Joined: Tue Oct 04, 2022 9:52 am

Registry value based on PROPERTY is not added when PROPERTY is assigned via DLL

Tue Nov 15, 2022 3:57 pm

Steps to reproduce the bug I experienced:
  1. Property View:
    1. Right click - New Property
      Name: PW_PROP
      Value: [EMPTY, thus delete everything in this field]
      Comments: Stores the encrypted password.
  2. Registry View:
    1. Right click on "HKEY_CURRENT_USER" - New Key - "HPASSWORD"
    2. Right click on the newly created HPASSWORD key - New Value:
      Name: Password
      Data: [PW_PROP]
  3. Organization View:
    Make sure the "HPASSWORD" and "Password" are assigned to the feature you are going to install (I assigned both to "Shared Files" so it's installed no matter which feature is selected).
  4. Inside Visual Studio 2017 create a new "Dynamic Link Library (DLL)" (C++) project, change the project properties such that it uses Unicode for the character set and use the following code:

    Code: Select all

    #include <msiquery.h>
    
    BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
    {
        switch (ul_reason_for_call)
        {
        case DLL_PROCESS_ATTACH:
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            break;
        }
        return TRUE;
    }
    EXPORT UINT __stdcall SetPW(MSIHANDLE Install)
    {
    	MsiSetProperty(Install, _T("PW_PROP"), _T("Super secret password"));
    	return ERROR_SUCCESS;
    }
  5. Custom Actions View:
    1. Add Custom Action - "Call function from attached native DLL"
      Attached DLL: Choose the DLL created in step 4.
      Function: There should be just the SetPW one - select it.
      Leave Action Data empty.
    2. Rename the Custom Action to "AssignPWViaDLL"
  6. Dialog View:
    1. Add a new control event to one of the dialogs' next button:
      Choose "Execute Custom Action", Argument: AssignPWViaDLL
  7. [Optional for debugging reasons] Add a Message Box custom action that prints the value of [PW_PROP] and add it also as control event to the same next button that was used in 6.
  8. Press the "Run the installer" button in the top icon bar.
    Click through the installer till the application is actually installed.
  9. Result
    1. Expected behavior: The registry key named "HPASSWORD" and the REG_SZ value "Super secret password" named Password are added to the registry.
    2. Actual behavior: The registry key named "HPASSWORD" and the REG_SZ value "" named Password are added to the registry. Thus, the password value is empty which it should not be!
    3. Dirty fix: A solution that I found is to set the initial value of PW_PROP inside the Property View to some value (just do not leave the Value field empty!).
Thanks in advance,
Johannes

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Registry value based on PROPERTY is not added when PROPERTY is assigned via DLL

Thu Nov 17, 2022 3:32 pm

Hello Johannes,

Are you creating, by any chance, an EXE setup?

Not quite sure, but I feel like I have faced this scenario in the past, I just can't seem to find any threads regarding it.

I remember this being like a limitation which we couldn't really "fix".

Anyway, I am glad you managed to find a workaround and thank you for sharing your solution with us.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

MGS
Posts: 83
Joined: Tue Oct 04, 2022 9:52 am

Re: Registry value based on PROPERTY is not added when PROPERTY is assigned via DLL

Mon Nov 21, 2022 1:19 pm

Catalin wrote:
Thu Nov 17, 2022 3:32 pm
Hello Johannes,

Are you creating, by any chance, an EXE setup?

Not quite sure, but I feel like I have faced this scenario in the past, I just can't seem to find any threads regarding it.

I remember this being like a limitation which we couldn't really "fix".

Anyway, I am glad you managed to find a workaround and thank you for sharing your solution with us.

Best regards,
Catalin
Hello Catalin,

Yes, I am creating a "Single EXE setup (resources inside)".
I understand, so I'll keep using my solution as is. You are welcome, hopefully this helps others facing the same problem in the future!

Best regards,
Johannes

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Registry value based on PROPERTY is not added when PROPERTY is assigned via DLL

Tue Nov 22, 2022 1:39 pm

For sure other users will find this useful!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”