Click here to Skip to main content
15,901,505 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 163K   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 
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 
I am not aware of any way to encrypt an msi. Although you could probably write your own algorithm to obfuscate the msi somehow, I think this would be very difficult to do, and the bottom line is that before the msiexec can run the setup, the msi would have to be decrypted back to it's "open" format somewhere on the target machine, so a savvy user could still find it and disable the PID checking anyway. So that would probably be pointless.

Another approach is to add a dialog to the bootstrapper Setup.EXE that performs the PID validation. This is pretty simple to do. The only problem with this is that presumably your msi is still "exposed" so a savvy user could simply run the msi directly and bypass the bootstrapper PID validation altogether. You could add a property to the msi that the bootstrapper sets to prevent running the msi directly, but this has the same problem as PID validation in the msi - a savvy user could probably examine the msi and figure out how to make it run anyway.

A third option which makes things pretty difficult for all but the most persistent hackers is to embed the msi in the Bootstrapper Setup.exe itself. The Setup.exe validates the PID, and only then does it extract the msi and run it. This approach would require a person to successfully decompile your Setup.exe to get at the msi.

I don't know much about combining and separating binary images from within a single running executable, but I know of one easy way to do this in C++. Just embed your msi in the Setup.exe as a custom resource, and then the Setup program can extract the msi image and copy it to the target machine just like it were an icon, etc. I don't know how easy this is to hack either, but it is at least a deterrent.

Finally you can do like XP - require the user to not only enter a PID but to register it on line. Of course this requires a lot more infrastructure to manage, and tends to not be very well received by a lot of users.

I have a legitimate copy of XP Pro. I use it only for testing setups and applications and troubleshooting. So when I need to use it, I generally need it to be as a "clean" OS install. The thought of having to actually make a phone call to MS to explain to them why everytime I need to use it I also need to install it on a clean machine, pisses me off to no end. So I simply never register it. I just install it on a clean partition if I need to test something, and after 30 days it becomes what I consider it to be in the first place - a totally useless piece of sh*t excuse for an OS.

You probably don't want to encourage your potential users to feel that way about your application. Smile | :)


-- modified at 14:26 Thursday 27th October, 2005
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.