Microsoft KB Archive/253683

From BetaArchive Wiki
Knowledge Base

How To Validate a Serial Number During an Installation Created with VSI

Article ID: 253683

Article Last Modified on 7/15/2004


  • Microsoft Visual Studio Installer 1.0
  • Microsoft Visual Studio Installer 1.1

This article was previously published under Q253683


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


  1. Create an empty installer project with VSI.
  2. Add a Customer Information dialog box to the user interface. Do not change the default properties for the dialog box.
  3. Build the project.
  4. 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.

  5. 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.
  6. 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
          MsiSetProperty(hInstall, "PIDCHECK", "FALSE");
          wsprintf(szText, "Please enter the correct code");
          MessageBox(NULL, szText, "PIDCHECK", MB_OK | MB_ICONINFORMATION);
       return 0;
  7. Open the Microsoft Windows installer package (.msi) file that you built with VSI in Orca.
  8. Add the DLL to the Binary table and name it VerifyPIDDll.
  9. Add a new custom action to the Custom Action Table:

    Name - MyPIDChecker;
    Type - 1; Source - VerifyPIDDll; Target - VerifyPID

  10. 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:
    1. Replace the ValidateProductID Event with DoAction. On the same row, replace the Argument {} with MyPIDChecker.
    2. Make sure that the value for the Condition column in the row with the EndDialog event is:

      UserNameForm_NextArgs="" AND UserNameForm_ShowSerial=""

    3. 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<>""

    4. Make sure that the value for the Condition column in the row with the [UserNameForm_ShowSerialDisabled] event is:


  11. Save the .msi file and run the installation.


For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

255905 How To Use the Orca Database Editor to Edit Windows Installer Files

Keywords: kbhowto KB253683