View Full Version : MsiGetProperty

08-26-2011, 01:51 PM
nLEN must now be assigned before calling MsiGetProperty in InstallScript

09-08-2011, 04:17 PM
Thanks for pointing that out. This change in behavior is now explained in KB article Q211163 (Upgrading Projects to InstallShield 2012) (http://support.installshield.com/kb/view.asp?articleid=Q211163). See the "Changes in Behavior for Some MSI APIs That Are Called in InstallScript Custom Actions" section of this article for more background.

10-03-2011, 02:23 AM
When I try to open Q211163 I get a blank page (I am succesfully logged in to the support portal).

10-03-2011, 08:24 AM
Hmm. That's weird. You should be able to see that KB article regardless of whether you are logged in. The URL that I provided above is a redirect URL. It seems to be working now, but maybe it wasn't redirecting for some reason when you tried it, or maybe your browser is blocking the redirect somehow.

Try this direct link:

10-03-2011, 08:52 AM
I have tried again from two different machines and can still not access Q211163. I am running Internet Explorer 9.0 and have no idea what could be causing the problem.

10-03-2011, 09:03 AM
Hmm. I'm not sure what's going on. I'll have someone look into it. In the meantime, here's the applicable content from the KB article:

Changes in Behavior for Some MSI APIs That Are Called in InstallScript Custom Actions
A change was made to how the InstallScript engine calls Windows Installer API such as MsiGetProperty. The engine now calls the Windows Installer APIs directly instead of using wrapper APIs that in turn call the Windows Installer APIs. This change was made to resolve issues with buffer handling and buffer sizes. It applies to all new projects that you create in InstallShield 2012, as well as projects that you have upgraded from earlier versions of InstallShield to InstallShield 2012.

As a result of this change, you can use the MSI install handle that is passed to a custom action function with all Windows Installer APIs that require an install handle. Previously, the handle was managed by the InstallScript engine, and it could not be passed directly to Windows Installer APIs.

Also as a result of this change, any Windows Installer APIs that require a buffer size to be specified now fail if the buffer size is not correctly specified. Note that 0 is not a valid size; thus, ensure that your code does not pass a zero value for the size of the buffer.

If you have existing InstallScript custom actions that call Windows Installer APIs, ensure that a large enough buffer size is specified; if it is not, unexpected results could occur.

The following sample code demonstrates how to retrieve the value of a Windows Installer property value string in InstallScript and increase the size of the buffer if necessary.

prototype STRING MyGetProperty (HWND, STRING);
// MyGetProperty
// Return an MSI property string value
// Input Parameters:
// hMSIHandle: Handle to the currently running MSI database
// szPropertyName: Name of property to retrieve
// Output:
// String containing the property value

function STRING MyGetProperty (hMSIHandle, szPropertyName)
NUMBER nvBuf, nResult;
STRING szReturn;

//Retrieve the size of the property value szReturn = "";
nResult = MsiGetProperty (hMSIHandle, szPropertyName, szReturn, nvBuf);

if (ERROR_MORE_DATA == nResult) then
nvBuf = nvBuf + 1; //increment buffer size for terminating null

//Retrieve the property value
nResult = MsiGetProperty (hMSIHandle, szPropertyName, szReturn, nvBuf);

if (nResult != ERROR_SUCCESS) then
szReturn = "";
return szReturn;

Note that if the script had used if ( ERROR_MORE_DATA == nResult ) then instead of if ( ERROR_MORE_DATA == nResult ) then, unexpected results could occur.

10-03-2011, 02:55 PM
It sounds like if you want to view the KB articles in IE 9, you'll need to have compatibility mode turned on.

Both Chrome and Firefox can display KB articles, so they may be other options to consider.

Christopher Painter
02-13-2012, 04:27 PM
Can someone at InstallShield explain the rational for why this change was made? While I understand how the MSI API works in a C/C++ world, InstallScript is supposed to be a higher level language and we've always ( 13 years? ) been able to make this API calls without having to do silly things like set nBufferSize since InstallScript doesn't require you to size string buffers in the first place. ( Well, atleast not since InstallShield 3 as I recall... )

Short of a really good explanation, I would describe this change as a bug not an improvement.

02-14-2012, 09:31 AM
It's both. Previously you didn't really have to set nBufferSize because we ignored it and used a relatively high value. However this means when you legitimately had a really long property value, it couldn't be read. The "fix" for the latter part broke the first part. Personally I think there's a better middle ground to be found, perhaps use the larger of the previous value and the passed value.