如何通过自定义操作读取包代码

时间:2013-08-20 10:58:57

标签: installation windows-installer installshield-2012

是否可以通过自定义操作读取包代码,如读取ProductCode和ProductName。我想删除在%LOCALAPPDATA%/ Downloaded Installations / GUID中创建的MSI缓存,其中GUID是卸载期间的包代码。

2 个答案:

答案 0 :(得分:0)

让我们一起来看看吧。首先,我们必须回答包裹代码的存储位置。 Package Codes在第三段中介绍了这一点:“包裹代码存储在摘要信息流版本号摘要属性中。”好的,那我们怎么读呢? Using the Summary Information Stream涵盖了这一点,您可以通过调用MsiGetSummaryInformation开始。但是这个代码将从自定义操作中调用,所以让我们验证它没关系。 Functions not for Use in Custom Actions涵盖了这一点。扫描列表时我们没有提到摘要信息函数(除了MsiCreateTransformSummaryInfo,我们这里不需要)。

是的,这是可能的。

答案 1 :(得分:0)

你可能想看一下我写回来的这段代码:(整个帖子读得很好)

Local cached MSI does not get deleted when uninstalling

<CustomAction Id="PurgeCache_CAD_Install"  Execute="immediate" Property="PurgeCache" Value="/CacheRoot=[CommonAppDataFolder]Downloaded Installations\MyCompany\MyProduct /PackageCode=[PackageCode] /InstallMode=Install"/>
<CustomAction Id="PurgeCache_CAD_Uninstall" Execute="immediate" Property="PurgeCache" Value="/CacheRoot=[CommonAppDataFolder]Downloaded Installations\MyCompany\MyProduct /PackageCode=[PackageCode] /InstallMode=UnInstall"/>
<InstallExecuteSequence>
  <Custom Action="PurgeCache_CAD_Install" After="ScheduleReboot">Not REMOVE="ALL"/>
  <Custom Action="PurgeCache_CAD_Uninstall" After="ScheduleReboot">REMOVE="ALL"/>
</InstallExecuteSequence>

export prototype PurgeCache(HWND);  

function PurgeCache(hMSI)

    number nResult; 
    string szInstallMode;           
    string szCacheRoot;
        string szDir;
        string szPackageCode;
    LIST listDirs;   

begin

    szInstallMode = MsiGetCustomActionDataAttribute( hMSI, "/InstallMode=" );   
    szCacheRoot = MsiGetCustomActionDataAttribute( hMSI, "/CacheRoot=" );
    szPackageCode = MsiGetCustomActionDataAttribute( hMSI, "/PackageCode=" );

    listDirs = ListCreate (STRINGLIST);
    FindAllDirs( szCacheRoot, EXCLUDE_SUBDIR, listDirs );
    nResult = ListGetFirstString (listDirs, szDir);
    while (nResult != END_OF_LIST);  

        if ( szInstallMode = "Uninstall" || !( szDir % szPackageCode )) then
            DeleteDir( szDir, ALLCONTENTS );
        endif;
        nResult = ListGetNextString (listDirs, szDir);

    endwhile;

 return ERROR_SUCCESS;

end;