Change the installation path with msi API

153 Views Asked by At

I'm trying to set installation path manually, with these lines of code,

MSIHANDLE msiHandle;
UINT openPackageExitCode = MsiOpenPackage(LR"(path to .msi file)", &msiHandle);
LPCTSTR newPath = LR"(C:\test\)";
UINT changePathResult = MsiSetTargetPath(msiHandle, L"INSTALLDIR", newPath);
MsiCloseHandle(msiHandle);

but, I get an error which says ERROR_DIRECTORY.

How can I change the installation path with this method?

1

There are 1 best solutions below

0
On

Calling MsiSetTargetPath in a custom action after CostFinalize action solved my problem.