Visual Studio2010 使用msi.h

本文介绍如何使用C++和Windows Installer API查询特定产品的安装状态。通过MsiQueryProductState函数,可以判断产品是否已安装、广告宣传但未安装等状态,并输出相应信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在#include <msi.h>的前面必须引用windows.h

源码如下:

//stdafx.h


#pragma once

#include "targetver.h"

#include <Windows.h>
#include <msi.h>
#include <MsiQuery.h>
#include <iostream>
#include <stdio.h>
#include <tchar.h>


//testmsi.cpp

#include "stdafx.h"

#pragma comment(lib,"Msi.lib")

int _tmain(int argc, _TCHAR* argv[])
{
    INSTALLSTATE state = MsiQueryProductState(_T("{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}"));

    if(state == INSTALLSTATE_ABSENT)
    {
        std::cout<<_T("The product is installed for a different user")<<std::endl;
    }
    else if(state == INSTALLSTATE_ADVERTISED)
    {
        std::cout<<_T("The product is advertised but not installed")<<std::endl;
    }
    else if(state == INSTALLSTATE_DEFAULT)
    {
        std::cout<<_T("The product is installed for the current user")<<std::endl;
    }
    else if(state == INSTALLSTATE_INVALIDARG)
    {
        std::cout<<_T("An invalid parameter was passed to the function")<<std::endl;
    }
    else if(state == INSTALLSTATE_UNKNOWN)
    {
        std::cout<<_T("The product is neither advertised or installed")<<std::endl;
    }

    std::cout<<state<<std::endl;
    
    system("PAUSE");
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值