Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading current installed version of an application using windows api

Tags:

c#

windows

winapi

I was trying to use windows api to find out the version info of an installed application.

I used the upgrade code to find out the product code using MsiEnumRelatedProducts api, but when I try to use MsiGetProductInfo using the product code, the version info comes back as garbage.

Here is my MsiGetProductInfo api:

[DllImport("msi.dll", CharSet = CharSet.Unicode)]
private static extern Int32 MsiGetProductInfo(
    string product, string property, [Out] StringBuilder valueBuf,
    ref Int32 len);

MsiGetProductInfo(sbProductCode, "INSTALLPROPERTY_INSTALLVERSION", builder, ref len);

Any thoughts on what I'm doing wrong?

like image 308
alice7 Avatar asked Aug 26 '26 10:08

alice7


2 Answers

In response to @JoshHetland the string to pass is the CamelCase postfix of the INSTALLPROPERTY_VERSIONSTRING - remember that MSI is case sensitive.

So:

INSTALLPROPERTY_VERSIONSTRING becomes VersionString

INSTALLPROPERTY_INSTALLDATE becomes InstallDate

and so on.

Complete list of properties available is on the MSDN page for the MsiGetProductInfo function .

like image 76
Damon D Avatar answered Aug 28 '26 02:08

Damon D


Here is what I did that my solved my problem.

        Int32 m_len = 11512;
        StringBuilder m_versionInfo = new StringBuilder(m_len);

        StringBuilder m_sbProductCode = GetProductCodeFromMsiUpgradeCode();
        MsiGetProductInfo(m_sbProductCode.ToString(), "**VersionString**", m_versionInfo, ref m_len);

        return m_versionInfo.ToString();

This did return me the version string ,and also converted from decimal into string format like 1.4.3.

like image 41
alice7 Avatar answered Aug 28 '26 00:08

alice7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!