473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to create .msi package with serial number validation?

1
hello,
i am very new to vc++.i have the code.
Expand|Select|Wrap|Line Numbers
  1. #include "windows.h"
  2. #include "stdafx.h"
  3.  
  4. // Need the following header files to access the MSI API
  5.  
  6. #include "msi.h"
  7. #include "msiquery.h"
  8. #pragma comment(lib, "msi.lib")
  9.  
  10. // Export the function so MSI can call it using undecorated C style name
  11. extern "C" _declspec(dllexport) UINT __stdcall VerifyPID(MSIHANDLE hInstall);
  12.  
  13.  
  14. // Private Function definitions
  15. TCHAR* GetPIDValue(TCHAR*);
  16.  
  17. extern "C" UINT __stdcall VerifyPID(MSIHANDLE hInstall)
  18. {
  19.    // Local variables
  20.    UINT    nRetVal = 0;
  21.    UINT    uiMsiRc;
  22.    TCHAR   szPidKey[MAX_PATH];
  23.    TCHAR   szSourceDir[MAX_PATH];
  24.    TCHAR*  lpszPidValue;
  25.    DWORD   dwBuffer;
  26.  
  27.    // Get the source folder for the msi project
  28.    dwBuffer = sizeof(szSourceDir)/sizeof(TCHAR);
  29.  
  30.    uiMsiRc = MsiGetProperty(hInstall, TEXT("SourceDir"), szSourceDir, &dwBuffer);
  31.  
  32.    if (ERROR_SUCCESS != uiMsiRc)
  33.    {
  34.       MessageBox(NULL, "Not able to retrieve the SourceDir property.  The setup may be corrupt.  Please contact Technical Support.", "Setup Error", MB_OK | MB_ICONEXCLAMATION);
  35.       return 0;
  36.    }
  37.  
  38.    // Call function to decrypt the PID to validate against from a file stored on setup media
  39.    lpszPidValue = GetPIDValue(szSourceDir);
  40.  
  41.     // Get the PIDKEY property value entered by the user from the active msi
  42.    dwBuffer = sizeof(szPidKey)/sizeof(TCHAR);
  43.  
  44.    uiMsiRc = MsiGetProperty(hInstall, TEXT("PIDKEY"), szPidKey, &dwBuffer);
  45.  
  46.    if (ERROR_SUCCESS != uiMsiRc)
  47.    {
  48.       MessageBox(NULL, "Not able to retrieve PIDKEY property.  The setup may be corrupt.  Please contact Technical Support.", "Setup Error", MB_OK | MB_ICONEXCLAMATION);
  49.       return 0;
  50.    }
  51.  
  52.    //Insert code to check PIDKEY here
  53.    int str = lstrcmp(szPidKey, lpszPidValue);
  54.  
  55.    //If PIDKEY passes check
  56.    if (str == 0)
  57.       MsiSetProperty(hInstall, "PIDCHECK", "TRUE");
  58.    //If PIDKEY doesn't pass check
  59.    else
  60.    {
  61.       MsiSetProperty(hInstall, "PIDCHECK", "FALSE");
  62.       MessageBox(NULL, "Please enter the correct product registration code!", "Invalid Key", MB_OK | MB_ICONINFORMATION);
  63.    }
  64.  
  65.    return 0;
  66. }
  67.  
  68. // GetPIDValue is used to locate and decrypt a key file on the setup media
  69. //  that contains the PID string to validate against.
  70.  
  71. TCHAR* GetPIDValue(TCHAR* lpszSourceDir)
  72. {
  73.     // lpszSourceDir contains the fully qualified path to the location where the setup is running.  
  74.     // For example, suppose the msi is located on a CD in the folder "\Setup\MySetup.msi".
  75.     // The user is running the CD in the D: drive.  
  76.     // lpszSourceDir will have a value of "D:\Setup\".  
  77.     // Note that the trailing slash is included!
  78.  
  79.     // TO DO: Concatenate key file path, example lpszSourceDir + "MyKeyFile.dat"
  80.     // TO DO: Read key file from source media
  81.     // TO DO: Code decryption algorithm for key file
  82.     // For this example, simply return a literal PID key of format <### - #######>
  83.  
  84.         return "123 - 4567890";
  85. }
how can i attach "MyKeyFile.dat" which i given in comment line.

thanks in advance,
Jun 9 '09 #1
0 4187

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: tom | last post by:
Hi, How do I get the serial number of the harddisk in .NET? I want this to be the same number even if the user has reformatted, so I do not want the volume serial number. Thanx, t
79
by: Klaus Bonadt | last post by:
In order to protect software from being copied without licence, I would like to use something like a key, which fits only to the current system. The serial number of the CPU or the current...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
1
by: Paul | last post by:
Hi Guys, I have written an application in Visual C#, I wish to add serial number validation dll to the installer, how do I go about doing this. Thanks in advance. Paul Mathebula
4
by: Yavuz Bogazci | last post by:
Hi, we are developing an winforms application for task management. We want generate a serial number wich includes Username, Company Name and another Information as String. How can i create from...
1
by: CJM | last post by:
I'm working on my first Oracle DB, so bear with me... I have a couple of validation routines which are both returning the same result regardless of the inputs. One checks if a Serial No already...
9
by: Nebojsa4 | last post by:
Hi. First, sorry on my weak English to all. Qusetion: How to read (in VB) Manufacturer serial number of Hard disk drive? Not volume/serial number of C:, D:, etc. partitons. For reading...
2
by: sheperson | last post by:
Hi, I have been working for several months on a sofware and now it is finished. I have a problem now and it is this: Because I live in a country which there is no copyright law in it (Iran!!!!)....
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.