Click here to Skip to main content
15,886,816 members
Articles / Programming Languages / C++
Article

How to Validate a Serial Number or PID in MSI Setups Created in VS.NET

Rate me:
Please Sign up or sign in to vote.
2.81/5 (12 votes)
8 Jun 20055 min read 162.8K   3.4K   71   30
Describes how to create a custom action DLL and implement serial number or PID validation in dialog based setups created with VS.NET.

Introduction

The MSDN article Q253683 describes how to validate a serial number during an MSI install created with VSI 1.1. However, the architecture of the MSI has changed somewhat in VS.NET and the instructions given for creating the custom action DLL may be difficult to follow for developers who are not experienced C++ programmers.

This article outlines how to adapt the procedure to an MSI created with VS.NET, and also gives detailed instructions on how to compile the custom action DLL.

Background

There are a wide variety of product registration strategies.

On one end of the spectrum are the typical "try-and-buy" techniques used with relatively small Internet download applications. The simplest technique is creating two downloads, one for the trial and one for the purchased product. More sophisticated methods usually involve embedding the registration code within the application itself, and rely on registry entries to determine when the trial ends or if a license has been obtained.

At the other end of the spectrum are shrink wrapped mass produced media that require a product key (PID) such as those Microsoft employs for its products.

Neither of these cases require special packaging skills from the typical developer. In the first case, the registration is achieved by familiar techniques - simply programming the trial and registration code into the app itself. The latter case invariably is handled by a department that exists solely for deployment management, and the code developers are not part of the process.

Occasionally, the developer themselves need to create media such as CDs for distribution without having the benefit of support from a dedicated group. This presents a problem for the app developer who generally does not have a lot of packaging expertise. This article is for the developer who needs to create a small number of media and wishes to require the user to enter a product key during the setup.

A simple technique that is manageable for a small number of deployment media is to create a product key file that uses some sort of encryption, and include it on the distribution media. The setup can then be modified to include a custom action that reads the product key file and validates the product key entered by the user.

This technique is outlined here.

Philosophy of licensing

This is not a discussion of licensing strategies, however one concept merits discussion. Some developers spend an undue time and effort trying to ensure their product is not used without a valid license. This is a futile endeavor.

The simple try-and-buy strategies are used to encourage most people to simply buy a relatively inexpensive product rather than using it illegally. But anyone who has a good working knowledge of the registry and programming techniques can figure out how to circumvent a trial period restriction. The philosophy here is that most people do not have this expertise, and besides, how much effort is it worth to avoid paying $39.95 for a spyware utility?

On the other hand, there is real interest in protecting higher value products like those marketed by Microsoft. But it is simply not feasible! Obviously, if you require a product key, you must supply the key with the media, and there is no way to prevent people from simply making copies of the product. So why do companies like MS invest the considerable resources required to create mass media with license keys? There are several reasons. The ROI comes not from the license key, but rather from the serial number! It is reasonable to assume that while many people who acquire legal software never actually register it, many do register. And that provides MS with valuable marketing information about how their products are acquired, because each time a product is registered, MS can look at the serial number and determine if the product was acquired as an OEM included with a new computer, a standalone shrink-wrapped app such as MS Word that was purchased from a vendor, or a shrink-wrapped suite of products like Office that was purchased from a vendor. All this information helps drive how they price, package, and distribute their products!

Also, having a standard process for generation of license keys and media makes it much simpler to prosecute bootlegged illegal products, but in practical terms this is much less of a consideration than acquiring marketing demographics.

Realistically, requiring a user to have a valid license key using the technique described in this article does very little to keep unlicensed copies from being made. So why bother? In my opinion, the reason is mainly if you create media for distribution of your product, users tend to expect a license key. Including this is mostly about creating a professional, high quality presentation for your product deployment. But you should understand that in terms of preventing unlicensed use of your product, the big boys have never been able to accomplish this and neither will you! Sorry, but that is the way it is!

About the Code

The download contains an HTML page that describes how to implement product key validation using a custom action DLL in MSI deployments created in VS.NET. The example DLL code simply uses a hard coded PID key value, but outlines the basic steps required to read this key from a file included with your setup.

The project and the source code for creating the custom DLL in VS.NET C++ is also included, along with more detailed instructions than the original MSDN article contained, in case you are not an experienced C++ developer.

A sample MSI that has been modified to perform PID validation is also included so that you can examine the MSI of a typical modified package in Orca.

To perform the modifications you will need a C++ compiler to create the DLL. The article describes the specifics for using VS.NET C++. Although creating the project and setting the compiler options are slightly different, the source code also works in VC++ 6.

You will also need to have the Windows Installer SDK installed, which is free for download.

Finally, the VS.NET IDE creates a dialog where the PID is labeled as "Serial Number". You will probably want to change this to "Product Registration Key", or "Product License Key", etc.. I leave this as an exercise for the reader. If you follow the instructions for the implementation as shown, you should be able to easily figure out how to modify the dialog label text.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I've worked in the chemical industry, nuclear power industry, and now healthcare (in that order).

My specialized area of IT interest is installer technologies.

Comments and Discussions

 
QuestionHow to make License for my C#.Net Windows Application Pin
Mohsin Afzal14-Jul-15 21:45
professionalMohsin Afzal14-Jul-15 21:45 
Questionmsi with serial number check: msi hangs when correct number is put in Pin
RaymondM3-Jan-12 7:35
RaymondM3-Jan-12 7:35 
GeneralSetup does not proceed Pin
jack_200930-Mar-09 1:43
jack_200930-Mar-09 1:43 
Hi you have certainly done a gr8 job.

I have done every step as you have entioned. But when i run setup and enter a serial number setup does not continue. If i click Next button after entering valid serial nothing happens.

Can anyone help me
GeneralRe: Setup does not proceed Pin
jack_200930-Mar-09 2:08
jack_200930-Mar-09 2:08 
QuestionHow can I access a serial number after installation Pin
Member 345539824-Oct-08 15:04
Member 345539824-Oct-08 15:04 
QuestionCan I use this on Windows Vista? Pin
FilipAndersson7-May-08 18:27
FilipAndersson7-May-08 18:27 
QuestionCan not open input file "msi.lib" Pin
Rose Liao19-Nov-07 8:48
Rose Liao19-Nov-07 8:48 
QuestionRe: Can not open input file "msi.lib" Pin
santanu10-Jan-08 19:43
santanu10-Jan-08 19:43 
AnswerRe: Can not open input file "msi.lib" Pin
Antonio Dias6-Oct-08 1:00
Antonio Dias6-Oct-08 1:00 
QuestionTCHAR*? Pin
DJALFANC17-Oct-07 16:37
DJALFANC17-Oct-07 16:37 
AnswerRe: TCHAR*? Pin
rwestgraham18-Oct-07 11:51
rwestgraham18-Oct-07 11:51 
QuestionHow to set my own serial key Pin
Exelioindia9-Sep-07 23:46
Exelioindia9-Sep-07 23:46 
AnswerRe: How to set my own serial key Pin
DJALFANC17-Oct-07 16:41
DJALFANC17-Oct-07 16:41 
Questionproblem with Message Box Pin
Oleg Lit.4-Apr-06 16:29
Oleg Lit.4-Apr-06 16:29 
AnswerRe: problem with Message Box Pin
Oleg Lit.5-Apr-06 9:21
Oleg Lit.5-Apr-06 9:21 
GeneralRe: problem with Message Box Pin
rwestgraham12-Apr-06 21:33
rwestgraham12-Apr-06 21:33 
GeneralRe: problem with Message Box Pin
V.S.25-Sep-06 11:04
V.S.25-Sep-06 11:04 
GeneralRe: problem with Message Box Pin
V.S.25-Sep-06 11:18
V.S.25-Sep-06 11:18 
GeneralVery Good! ...Only One Security Problem... Pin
Daniël_T27-Oct-05 1:11
Daniël_T27-Oct-05 1:11 
GeneralRe: Very Good! ...Only One Security Problem... Pin
rwestgraham27-Oct-05 8:20
rwestgraham27-Oct-05 8:20 
Question[Message Deleted] Pin
Daniël_T27-Oct-05 12:22
Daniël_T27-Oct-05 12:22 
AnswerRe: Extended your code; ran into problems. C++ is a jungle!!! Pin
rwestgraham27-Oct-05 18:19
rwestgraham27-Oct-05 18:19 
GeneralRe: Extended your code; ran into problems. C++ is a jungle!!! Pin
Daniël_T27-Oct-05 21:55
Daniël_T27-Oct-05 21:55 
QuestionPlease if u can make a c# Copy ? Pin
Eng-Waheid13-Aug-05 22:55
Eng-Waheid13-Aug-05 22:55 
AnswerRe: Please if u can make a c# Copy ? Pin
rwestgraham11-Sep-05 14:26
rwestgraham11-Sep-05 14:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.