Reputation: 3650
I have a code that modifies a cached (not the one being installed) msi installer database which works fine when executed within a standalone exe. But when it is run from within an msi Custom Action I get an access violation that is very strange.
const auto& msiProductCode = ::GetProductCode(::msiUpgradeCode);
const auto& msiPath = ::GetCachedMSIPath(msiProductCode);
PMSIHANDLE dbHandle{};
const auto res = MsiOpenDatabaseW(msiPath.data(), MSIDBOPEN_TRANSACT, &dbHandle); // access violation here within msi castom aciton
The exception message:
Exception thrown at 0x76246E10 (rpcrt4.dll) in msiexec.exe: 0xC0000005: Access violation reading location 0x00000001.
What I can't understand is how it even ends up in the rpcrt4.dll
, since a standalone executable does not have that dependency:
Dump of file .\disable_custom_action.exe
File Type: EXECUTABLE IMAGE
Image has the following dependencies:
msi.dll
MSVCP140D.dll
VCRUNTIME140D.dll
VCRUNTIME140_1D.dll
ucrtbased.dll
KERNEL32.dll
The dll for the msi custom action, however, has this dependency due to the use of RPC in other
Custom Action functions. In-Script execution
for this Custom Action is configured to Immediate Execution
.
1 What might cause the access violation within when running withinthe msi Custom Action?
2 Can MsiOpenDatabaseW
somehow depend on rpcrt4.dll
?
3 Can it be caused by a possible inconsistence in C/Cpp Runtime linkage (different CRT versions)?
My initial problem is described here. I though that I figured it out, before the answer revealed the part where I can't call MsiOpenDatabaseW
during an active installation.
Upvotes: 2
Views: 209
Reputation: 21896
You can't use MsiOpenDatabase
from a custom action:
Because MsiOpenDatabase initiates database access, it cannot be used with a running installation.
Upvotes: 1