none
我写了一段代码 本意是想获取用Windows Installer安装的程序的相关信息。但是它却无法工作~ RRS feed

  • 常规讨论

  • 我写了一段代码 本意是想获取用Windows Installer安装的程序的相关信息,比如获取UninstallString和类似NoRemove、NoModify、NoRepair属性,有哪位高人来指点一下?
    typedef enum ITEM_COMEFROM_tag
    {
    	FROM_MSI, 
    	FROM_HKLM, 
    	FROM_HKCU
    }ITEM_COMEFROM;
    
    typedef struct SOFTITEM_tag
    {
    	CString szSoftName;
    	CString szClassID;
    	CString szUninstallString;
    	CString szRegKey;
    	BOOL bNoModify;
    	BOOL bNoRemove;
    	BOOL bNoRepair;
    	BOOL IsHotFix;
    	ITEM_COMEFROM iComeFrom;
    }SOFTITEM;
    
    typedef std::vector<SOFTITEM> TSOFTLIST;
    
    TSOFTLIST m_SoftList;

    void CCollectUninstallDlg::GetMsiItem()
    {
    	wchar_t wsProductCode[39] = {0};
    	DWORD iIndex = 0;
    	DWORD dwContext = MSIINSTALLCONTEXT_USERMANAGED | MSIINSTALLCONTEXT_USERUNMANAGED | MSIINSTALLCONTEXT_MACHINE;
    	HRESULT dwRet = MsiEnumProductsEx(NULL, NULL, dwContext, iIndex, wsProductCode, NULL, NULL, NULL );
    
    	while (ERROR_SUCCESS == dwRet)
    	{
    		SOFTITEM Info;
    		wchar_t wsVaule[MAX_PATH] = {0};
    		DWORD dwNeedSize = MAX_PATH;
    
    		if (ERROR_SUCCESS == MsiGetProductInfoW(wsProductCode, INSTALLPROPERTY_PRODUCTNAME, wsVaule, &dwNeedSize))
    		{
    			Info.szSoftName = wsVaule;
    			Info.szClassID = wsProductCode;
    			Info.iComeFrom = FROM_MSI;
    			Info.IsHotFix = FALSE;
    			Info.bNoModify = FALSE;
    			Info.bNoRemove = FALSE;
    			Info.bNoRepair = FALSE;
    
    			dwNeedSize = MAX_PATH;
    			ZeroMemory(wsVaule, MAX_PATH);
    			if (ERROR_SUCCESS == MsiGetProductInfo(wsProductCode, L"NoModify", wsVaule, &dwNeedSize))
    			{
    				if (wsVaule == L"1")
    				{
    					Info.bNoModify = TRUE;
    				}
    			}
    
    			dwNeedSize = MAX_PATH;
    			if (ERROR_SUCCESS == MsiGetProductInfo(wsProductCode, L"NoRemove", wsVaule, &dwNeedSize))
    			{
    				if (wsVaule == L"1")
    				{
    					Info.bNoRemove = TRUE;
    				}
    			}
    
    			dwNeedSize = MAX_PATH;
    			if (ERROR_SUCCESS == MsiGetProductInfo(wsProductCode, L"NoRepair", wsVaule, &dwNeedSize))
    			{
    				if (wsVaule == L"1")
    				{
    					Info.bNoRepair = TRUE;
    				}
    			}
    
    			dwNeedSize = MAX_PATH;
    			if (ERROR_SUCCESS == MsiGetProductInfo(wsProductCode, L"UninstallString", wsVaule, &dwNeedSize))
    			{
    					Info.szUninstallString = wsVaule;
    			}
    			
    
    			m_SoftList.push_back(Info);
    
    		}
    
    		iIndex++;
    		dwRet = MsiEnumProductsEx(NULL, NULL, dwContext, iIndex, wsProductCode, NULL, NULL, NULL );
    	}
    }
    本以为使用MsiGetProductInfo(wsProductCode, L"NoModify", wsVaule, &dwNeedSize)这种方法能够得偿所愿,但是发现,执行到这一句的时候,返回的是S_OK,但是wsVaule中却还是NULL而不是注册表中所记录的1或者0~
    2009年12月12日 3:44

全部回复