Microsoft KB Archive/253683: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "&" to "&")
m (Text replacement - """ to """)
 
Line 68: Line 68:
</li>
</li>
<li>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.</li>
<li>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.</li>
<li><p>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 &quot;XXX -XXXXXXX&quot; 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:</p>
<li><p>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:</p>
<pre class="codesample">UINT __stdcall VerifyPID(MSIHANDLE hInstall)
<pre class="codesample">UINT __stdcall VerifyPID(MSIHANDLE hInstall)
{
{
Line 80: Line 80:


   // First Step - Get the PIDKEY property   
   // First Step - Get the PIDKEY property   
   uiMsiRc = MsiGetProperty(hInstall, TEXT(&quot;PIDKEY&quot;), szPidKey, &dwBuffer);  
   uiMsiRc = MsiGetProperty(hInstall, TEXT("PIDKEY"), szPidKey, &dwBuffer);  


   if (ERROR_SUCCESS != uiMsiRc)
   if (ERROR_SUCCESS != uiMsiRc)
   {
   {
       MessageBox(NULL, &quot;PIDKEY&quot;, &quot;Not able to retrieve PIDKEY property&quot;, MB_OK | MB_ICONEXCLAMATION);
       MessageBox(NULL, "PIDKEY", "Not able to retrieve PIDKEY property", MB_OK | MB_ICONEXCLAMATION);
       return 0;
       return 0;
   }
   }


   //Insert code to check PIDKEY here
   //Insert code to check PIDKEY here
   int str = lstrcmp(szPidKey, &quot;123 -4567890&quot;);
   int str = lstrcmp(szPidKey, "123 -4567890");


   //If PIDKEY passes check
   //If PIDKEY passes check
   if (str == 0)  
   if (str == 0)  
       MsiSetProperty(hInstall, &quot;PIDCHECK&quot;, &quot;TRUE&quot;);
       MsiSetProperty(hInstall, "PIDCHECK", "TRUE");
   //If PIDKEY doesn't pass check
   //If PIDKEY doesn't pass check
   else  
   else  
   {
   {
       MsiSetProperty(hInstall, &quot;PIDCHECK&quot;, &quot;FALSE&quot;);
       MsiSetProperty(hInstall, "PIDCHECK", "FALSE");
       wsprintf(szText, &quot;Please enter the correct code&quot;);
       wsprintf(szText, "Please enter the correct code");
       MessageBox(NULL, szText, &quot;PIDCHECK&quot;, MB_OK | MB_ICONINFORMATION);
       MessageBox(NULL, szText, "PIDCHECK", MB_OK | MB_ICONINFORMATION);
   }
   }


Line 120: Line 120:
<div class="indent">
<div class="indent">


<p>'''UserNameForm_NextArgs=&quot;&quot; AND UserNameForm_ShowSerial=&quot;&quot;'''</p>
<p>'''UserNameForm_NextArgs="" AND UserNameForm_ShowSerial=""'''</p>


</div></li>
</div></li>
Line 126: Line 126:
<div class="indent">
<div class="indent">


<p>'''(PIDCHECK=&quot;TRUE&quot;) AND UserNameForm_NextArgs<>&quot;&quot; AND UserNameForm_ShowSerial<>&quot;&quot;'''</p>
<p>'''(PIDCHECK="TRUE") AND UserNameForm_NextArgs<>"" AND UserNameForm_ShowSerial<>""'''</p>


</div></li>
</div></li>
Line 132: Line 132:
<div class="indent">
<div class="indent">


<p>'''PIDCHECK=&quot;TRUE&quot;'''</p>
<p>'''PIDCHECK="TRUE"'''</p>


</div></li></ol>
</div></li></ol>

Latest revision as of 13:52, 21 July 2020

Knowledge Base


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

Article ID: 253683

Article Last Modified on 7/15/2004



APPLIES TO

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



This article was previously published under Q253683

SUMMARY

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

MORE INFORMATION

  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
       else 
       {
          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:

      PIDCHECK="TRUE"

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


REFERENCES

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