- Property View:
- Right click - New Property
Name: PW_PROP
Value: [EMPTY, thus delete everything in this field]
Comments: Stores the encrypted password.
- Right click - New Property
- Registry View:
- Right click on "HKEY_CURRENT_USER" - New Key - "HPASSWORD"
- Right click on the newly created HPASSWORD key - New Value:
Name: Password
Data: [PW_PROP]
- 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). - 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; }
- Custom Actions View:
- 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. - Rename the Custom Action to "AssignPWViaDLL"
- Add Custom Action - "Call function from attached native DLL"
- Dialog View:
- Add a new control event to one of the dialogs' next button:
Choose "Execute Custom Action", Argument: AssignPWViaDLL
- Add a new control event to one of the dialogs' next button:
- [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.
- Press the "Run the installer" button in the top icon bar.
Click through the installer till the application is actually installed. - Result
- Expected behavior: The registry key named "HPASSWORD" and the REG_SZ value "Super secret password" named Password are added to the registry.
- 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!
- 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!).
Johannes