Version Check within Chef

I am having an issue with Chef reporting that an application has is “up to date” when in face the version number is different.

This may not be a chef bug it could be the way the msi (wix created with many custom actions). How does chef determine the previous installed version versus the current version.

Note I am using package (windows_package).

I have tried to put on debug on the chef run but it will only tell me the version number of the resource i am trying to install which it is picking up as correct.

Thanks,
Brian

If the windows_package resource you are using is from the Windows cookbook then the current version comes from an installed_packages collection which is built here

See extract_installed_packages_from_key

It looks in the Windows registry, the registry locations are documented on the Windows cookbook GitHub page

The source code for the Windows cookbook is public you can trace through what it is doing by tracking down the windows_package LWRP, I’d start by looking at the load_current_resource method which was the old LWRP method for obtaining the current state of a resource.

The windows_package that is built in to Chef operates differently.

The inbuilt windows_packages uses the excellent FFI library to make calls into the MSI package, the code is
get_product_property(new_resource.source, “ProductCode”)
get_product_property(new_resource.source, “ProductVersion”)

Where get_product_property is calling

UINT MsiGetProductProperty(
In MSIHANDLE hProduct,
In LPCTSTR szProperty,
Out LPTSTR lpValueBuf,
Inout DWORD *pcchValueBuf
);

https://msdn.microsoft.com/en-us/library/windows/desktop/aa370130(v=vs.85).aspx

NB: interrogating an MSI with these function calls will write to the Windows event log so it’s worth checking that too help determine which windows_package is being called.

To sum up what has been said here with some slight correction:

If you are using chef client version 12.6 or higher. The installed version for MSIs uses the win32 function MsiGetProductInfo and uses the VersionString property. For non MSIs (EXEs), the installed version comes from the DisplayVersion value in the registry key: Software\Microsoft\Windows\CurrentVersion\Uninstall in HKLM or HKCU.

Older clients that use the windows cookbook windows_package resource use almost the same logic except that MSIs also use the above mentioned registry value and not MsiGetProductInfo.