Domanda

Is it possible to read package code through custom action as reading ProductCode and ProductName. I want to remove the MSI cache being created in %LOCALAPPDATA%/Downloaded Installations/GUID, where GUID is the package code during uninstallation.

È stato utile?

Soluzione

You might want to take a look at this code I wrote awhile back: (the entire thread is a good read)

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;

Altri suggerimenti

Let's walk this through. First we have to answer where the package code is stored. Package Codes covers this in its third paragraph: "The package code is stored in the Revision Number Summary Property of the Summary Information Stream." Ok, so how do we read that? That's covered on Using the Summary Information Stream, where you start with a call to MsiGetSummaryInformation. But this code will be called from a custom action, so let's verify it's okay. Functions not for Use in Custom Actions covers this. Scanning the list we find no mention of the summary information functions (except MsiCreateTransformSummaryInfo which we don't need here).

So yes, this is possible.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top