I am using Windows MSI API to update the Package Code of an MSI package. I can successfully retrieve the package code without issues. However, the MsiSummaryInfoSetProperty()
call to set the new package code fails with error code 1627
. One issue is that PID_REVNUMBER
does not resolve to a known identifier, but PIDSI_REVNUMBER
does. Both PID_REVNUMBER and PIDSI_REVNUMBER resolve to the same constant. Other than that, can you spot any issues in the code snippet below?
#pragma comment(lib, "msi.lib")
#include <iostream>
#include <windows.h>
#include "msi.h"
#include "msiquery.h"
#include "oaidl.h"
int main()
{
UINT result;
MSIHANDLE hDatabase = NULL;
char msiPkg[] = "C:\mypkg.msi";
result = MsiOpenDatabase(msiPkg, MSIDBOPEN_DIRECT, &hDatabase);
if (result != ERROR_SUCCESS) {
std::cerr << "Failed to open MSI database. Error: " << result << std::endl;
return false;
}
// Get the summary information handle
MSIHANDLE hSummaryInfo = NULL;
result = MsiGetSummaryInformation(hDatabase, NULL, 0, &hSummaryInfo);
if (result != ERROR_SUCCESS) {
std::cerr << "Failed to get summary information. Error: " << result << std::endl;
MsiCloseHandle(hDatabase);
return false;
}
// Retrieve the package code
char packageCode[39]; // GUIDs are 38 characters + null terminator
DWORD packageCodeSize = sizeof(packageCode) / sizeof(packageCode[0]);
result = MsiSummaryInfoGetProperty(hSummaryInfo, PIDSI_REVNUMBER, NULL, NULL, NULL, packageCode, &packageCodeSize);
if (result != ERROR_SUCCESS) {
std::cerr << "Failed to get package code. Error: " << result << std::endl;
MsiCloseHandle(hSummaryInfo);
MsiCloseHandle(hDatabase);
return false;
}
std::cout << "Package code: " << packageCode << std::endl;
// Set the new package code
// https://learn.microsoft.com/en-us/windows/win32/msi/summary-information-stream-property-set
// https://learn.microsoft.com/en-us/windows/win32/stg/the-summary-information-property-set
char newPackageCode[] = "{B4CC3940-2CDD-4EFF-9B59-B7D6D838242E}";
result = MsiSummaryInfoSetProperty(hSummaryInfo, PIDSI_REVNUMBER, VT_LPSTR, 0, NULL, newPackageCode);
if (result != ERROR_SUCCESS) {
std::cerr << "Failed to set package code. Error: " << result << std::endl;
MsiCloseHandle(hSummaryInfo);
MsiCloseHandle(hDatabase);
return false;
}
// Persist changes to the summary information stream
result = MsiSummaryInfoPersist(hSummaryInfo);
if (result != ERROR_SUCCESS) {
std::cerr << "Failed to persist summary information. Error: " << result << std::endl;
MsiCloseHandle(hSummaryInfo);
return false;
}
// Clean up
MsiCloseHandle(hSummaryInfo);
MsiCloseHandle(hDatabase);
}
- Replace the
MsiSummaryInfoSetProperty()
call withpackageCode
instead ofnewPackageCode
- Tried different GUID values for
newPackageCode
The call still fails.