hello,
i am very new to vc++.i have the code.
how can i attach "MyKeyFile. dat" which i given in comment line.
thanks in advance,
i am very new to vc++.i have the code.
Code:
#include "windows.h"
#include "stdafx.h"
// Need the following header files to access the MSI API
#include "msi.h"
#include "msiquery.h"
#pragma comment(lib, "msi.lib")
// Export the function so MSI can call it using undecorated C style name
extern "C" _declspec(dllexport) UINT __stdcall VerifyPID(MSIHANDLE hInstall);
// Private Function definitions
TCHAR* GetPIDValue(TCHAR*);
extern "C" UINT __stdcall VerifyPID(MSIHANDLE hInstall)
{
// Local variables
UINT nRetVal = 0;
UINT uiMsiRc;
TCHAR szPidKey[MAX_PATH];
TCHAR szSourceDir[MAX_PATH];
TCHAR* lpszPidValue;
DWORD dwBuffer;
// Get the source folder for the msi project
dwBuffer = sizeof(szSourceDir)/sizeof(TCHAR);
uiMsiRc = MsiGetProperty(hInstall, TEXT("SourceDir"), szSourceDir, &dwBuffer);
if (ERROR_SUCCESS != uiMsiRc)
{
MessageBox(NULL, "Not able to retrieve the SourceDir property. The setup may be corrupt. Please contact Technical Support.", "Setup Error", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
// Call function to decrypt the PID to validate against from a file stored on setup media
lpszPidValue = GetPIDValue(szSourceDir);
// Get the PIDKEY property value entered by the user from the active msi
dwBuffer = sizeof(szPidKey)/sizeof(TCHAR);
uiMsiRc = MsiGetProperty(hInstall, TEXT("PIDKEY"), szPidKey, &dwBuffer);
if (ERROR_SUCCESS != uiMsiRc)
{
MessageBox(NULL, "Not able to retrieve PIDKEY property. The setup may be corrupt. Please contact Technical Support.", "Setup Error", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
//Insert code to check PIDKEY here
int str = lstrcmp(szPidKey, lpszPidValue);
//If PIDKEY passes check
if (str == 0)
MsiSetProperty(hInstall, "PIDCHECK", "TRUE");
//If PIDKEY doesn't pass check
else
{
MsiSetProperty(hInstall, "PIDCHECK", "FALSE");
MessageBox(NULL, "Please enter the correct product registration code!", "Invalid Key", MB_OK | MB_ICONINFORMATION);
}
return 0;
}
// GetPIDValue is used to locate and decrypt a key file on the setup media
// that contains the PID string to validate against.
TCHAR* GetPIDValue(TCHAR* lpszSourceDir)
{
// lpszSourceDir contains the fully qualified path to the location where the setup is running.
// For example, suppose the msi is located on a CD in the folder "\Setup\MySetup.msi".
// The user is running the CD in the D: drive.
// lpszSourceDir will have a value of "D:\Setup\".
// Note that the trailing slash is included!
// TO DO: Concatenate key file path, example lpszSourceDir + "MyKeyFile.dat"
// TO DO: Read key file from source media
// TO DO: Code decryption algorithm for key file
// For this example, simply return a literal PID key of format <### - #######>
return "123 - 4567890";
}
thanks in advance,