我试图从 C++ 自定义操作中获取“UILevel”MSI 属性,以确定用户是否在“无 UI 模式”下运行,但运气不佳。我正在调用的函数是从我在我的 DLL 中导出的函数(可能是“延迟”或“第一序列”操作)中传递给 MSIHANDLE 的。我看到的是它MsiGetPropertyW
总是返回ERROR_MORE_DATA
并且该trueLength
字段始终为0。这是我的代码:
bool runningInNoUIMode(MSIHANDLE hInstall)
{
unsigned long nBufLen = 64UL;
WCHAR *wszValue = new WCHAR[nBufLen];
DWORD trueLength = 0UL;
UINT result = ::MsiGetPropertyW(hInstall, L"UILevel", L"", &trueLength); // Get the size of the property value first to see if there is enough storage allocated.
if (ERROR_MORE_DATA == result || nBufLen <= trueLength)
{
if (NULL != wszValue)
{
delete [] wszValue;
}
// Allocate more memory for the property adding one for the null terminator.
nBufLen = trueLength + 1;
wszValue = new WCHAR[nBufLen];
}
if (NULL == wszValue)
{
WcaLog(LOGMSG_STANDARD, "Unable to determine the user interface level the MSI is being run with because we were unable to allocate storage for accessing the 'UILevel' property.");
return false;
}
memset(wszValue, L'\0', nBufLen * sizeof(WCHAR));
result = ::MsiGetPropertyW(hInstall, L"UILevel", wszValue, &trueLength);
if (ERROR_SUCCESS != result)
{
WcaLog(LOGMSG_STANDARD, "Unable to determine the user interface level the MSI is being run with, error code = '%lu'.", result);
delete [] wszValue;
return false;
}
if (0 == wcscmp(L"2", wszValue)) // INSTALLUILEVEL_NONE == 2
{
delete [] wszValue;
return true;
}
delete [] wszValue;
return false;
}
我相信我现在可以通过通过 WiX 传递“UILevel”属性并在 C++ 中以这种方式检查它来解决这个问题,但我很好奇这里的问题是什么。
我在带有 WiX 3.5.2519 的 Windows 7 上使用 Visual Studio/Visual C++ 2010。
感谢您提供的任何帮助!