使用 windows api 读取当前安装的应用程序版本 [英] Reading current installed version of an application using windows api

查看:49
本文介绍了使用 windows api 读取当前安装的应用程序版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 windows api 来找出已安装应用程序的版本信息.

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

我使用升级代码通过 MsiEnumRelatedProducts api 查找产品代码,但是当我尝试使用产品代码使用 MsiGetProductInfo 时,版本信息作为垃圾返回.

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.

这是我的 MsiGetProductInfo api:

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?

推荐答案

以下是我解决问题的方法.

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();

这确实返回了版本字符串,并且还从十进制转换为字符串格式,如 1.4.3.

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

这篇关于使用 windows api 读取当前安装的应用程序版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆