In a Visual Studio Installer (VSI) project, the developer has the ability to add a Customer Information dialog box in the user interface. By default, this dialog box has an input field for a serial number. Visual Studio Installer provides minimal support for validating this field. This article provides the steps necessary to include custom code to validate the serial number that is entered by the user. These steps include using the Windows Installer SDK tool Orca, and creating a DLL for which sample code is provided.
To download the Orca tool, see the following MSDN Web site that includes samples, tools, and documentation for the Windows Installer
Add a Customer Information dialog box to the user interface. Do not change the default properties for the dialog box.
Build the project.
Create a custom action DLL. NOTE: You cannot use an EXE custom action because this custom action sets a property and that can only be accomplished by using a DLL, which has a handle to the installation.
On the Tools menu, click the Options Directories tab in your DLL project, and then add the path to the Windows Installer SDK's Include and Lib directories.
In the Project Settings dialog box, add msi.lib to the library list. Use either a .DEF file or the __declspec(dllimport) attribute to export the DLL functions.
Note that the PIDKEY property has the value of "XXX -XXXXXXX" where X is a number and there is both a space and hyphen. The following sample code uses a string comparison to determine if the serial number is valid:
UINT __stdcall VerifyPID(MSIHANDLE hInstall)
{
// Local variables
UINT nRetVal = 0;
UINT uiMsiRc;
TCHAR szPidKey[MAX_PATH];
DWORD dwBuffer;
dwBuffer = sizeof(szPidKey)/sizeof(TCHAR);
// First Step - Get the PIDKEY property
uiMsiRc = MsiGetProperty(hInstall, TEXT("PIDKEY"), szPidKey, &dwBuffer);
if (ERROR_SUCCESS != uiMsiRc)
{
MessageBox(NULL, "PIDKEY", "Not able to retrieve PIDKEY property", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
//Insert code to check PIDKEY here
int str = lstrcmp(szPidKey, "123 -4567890");
//If PIDKEY passes check
if (str == 0)
MsiSetProperty(hInstall, "PIDCHECK", "TRUE");
//If PIDKEY doesn't pass check
else
{
MsiSetProperty(hInstall, "PIDCHECK", "FALSE");
wsprintf(szText, "Please enter the correct code");
MessageBox(NULL, szText, "PIDCHECK", MB_OK | MB_ICONINFORMATION);
}
return 0;
}
Open the Microsoft Windows installer package (.msi) file that you built with VSI in Orca.
Add the DLL to the Binary table and name it VerifyPIDDll.
Add a new custom action to the Custom Action Table:
Name - MyPIDChecker;
Type - 1; Source - VerifyPIDDll; Target - VerifyPID
In the ControlEvent table, find the UserNameForm, which corresponds to the
Customer Information dialog box from VSI. Make all changes to the existing rows with UserNameForm in the Dialog column and Next in the Control column:
Replace the ValidateProductID Event with DoAction. On the same row, replace the Argument {} with MyPIDChecker.
Make sure that the value for the Condition column in the row with the EndDialog event is:
UserNameForm_NextArgs="" AND UserNameForm_ShowSerial=""
Using the PIDCHECK property which was set in the precious sample code, make sure that the value for the
Condition column in the row with the NewDialog event is:
(PIDCHECK="TRUE") AND UserNameForm_NextArgs<>"" AND UserNameForm_ShowSerial<>""
Make sure that the value for the Condition column in the row with the [UserNameForm_ShowSerialDisabled] event is:
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.