cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
DataAnalyzer
Level 8

Can't programmatically get ProductVersion

I need to get the product version of the current build but these attempts don't work

szBuild = @ProductVersion

or
MsiGetProperty(ISMSI_HANDLE, "ProductVersion", szBuild, nSize);

Actually, I'm not even sure why I use the ISMSI_HANDLE parameter. I think I saw it in an example somewhere.

How do I get this property which is set on the property sheet for the build.

I can get the product name without a problem.
Labels (1)
0 Kudos
(6) Replies
RobertDickau
Flexera Alumni

For an MSI project, you should be able to get the value of ProductVersion (or any other property) in the usual places. (You'll need to go through CustomActionData if you're getting the value during deferred mode, for example.)

The help topic "ISMSI_HANDLE" describes where and why to use that in MSI function calls.
0 Kudos
DataAnalyzer
Level 8

I don't know what you mean by "usual places". I thought the two ways I tried were the usual places.

Can you give the exact way to get the Version number? The help file doesn't show an example and it's different from how to get the Product Name which would appear to be a similar type of property.
0 Kudos
RobertDickau
Flexera Alumni

The @Something format is just for string-table entries. The MsiGetProperty technique does the trick in more places (for MSI properties, of course), and for event handlers such as OnBegin, the "ISMSI_HANDLE" help topic has an example.

For InstallScript custom actions (where you prototype "export prototype something(HWND); ... function something(hMSI)..."), the InstallShield help topic "Getting and Setting Properties" has a similar example.
0 Kudos
DataAnalyzer
Level 8

I'm really sorry for bothering you and feel like a complete idiot but for whatever reason, I can't seem to get the version property.

I have this code in OnBegin:

STRING svBuild[256];
NUMBER nSize;
....
MsiGetProperty(ISMSI_HANDLE, "PRODUCTVERSION", svBuild, nSize);

but svBuild is always blank.


I spelled the property name as "ProductVersion" and also ALL CAPS, and it didn't make a difference.

What am I missing?

Sorry for being so stupid, but can you give me the actual code? What I entered above and originally is what I thought the help file suggested.
0 Kudos
RobertDickau
Flexera Alumni

Case does matter (ProductVersion, not PRODUCTVERSION, for example), so perhaps try this in an InstallScript MSI project:

function OnBegin( )
STRING sProductVersion;
NUMBER nSize;
begin

nSize = 256;
MsiGetProperty(ISMSI_HANDLE, "ProductVersion", sProductVersion, nSize);

MessageBox("ProductVersion = " + sProductVersion, INFORMATION);

end;


Part of the trick is to make sure the nSize value is large enough to hold the largest value that could come back. We should really follow the idiom of calling MsiGetProperty once to get the buffer size (it'll return ERROR_MORE_DATA the first time), and then call it again to fill in the buffer; but common practice seems to be to lead in with an nSize value that would hold any string we expect to get back and call MsiGetProperty only once.
0 Kudos
DataAnalyzer
Level 8

Thanks! It's now working.

I was missing the setting of the nSize parameter before calling the routine. Based on the definition of it being an inout parameter, I didn't realize it needed to be set in advance.

It'd be nice to have your example in the help file. Would have saved a lot of frustration.

Thank you very much!
0 Kudos