FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Dobbs M-Dev
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
March 01, 2001

Customizing Windows Installer

(Page 17 of 24)
March 2001/Customizing Windows Installer/Listing 6

Listing 6: listobjs.cpp — Enumerating Platform SDK components

// ListObjs.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <msi.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
    FILE *listdata;
    listdata = fopen  ("lstobjs.txt" , "w"); 

    char cbuff [100];
    char pbuff[100];
    char pathbuff [MAX_PATH];
    char descbuff [500]; 
    const char psdkproduct [] = "{FB392771-9E4A-4DF8-9262-080BD65C0967}";

    INSTALLSTATE sval = MsiQueryProductState (psdkproduct); 
    if (sval != INSTALLSTATE_DEFAULT)
    {
        fprintf (listdata, "Platform SDK not installed\n");
        return 0;
    }
    DWORD dwdescbuff = sizeof(descbuff);
    UINT pi = MsiGetProductInfo (psdkproduct, 
        INSTALLPROPERTY_INSTALLEDPRODUCTNAME, 
        descbuff, &dwdescbuff);
    fprintf (listdata, "%s \n", descbuff);
    DWORD ix = 0; 
    for (ix=0; 1; ix++)
    {
        UINT urc;
        urc = MsiEnumComponents (ix, cbuff);
        if (ERROR_SUCCESS!=urc)
            break;
        UINT urp = MsiGetProductCode (cbuff, pbuff); 
        if (_stricmp (psdkproduct, pbuff) ==0)
        {
            DWORD dwpathbufflen = sizeof (pathbuff);
            INSTALLSTATE ival = MsiGetComponentPath (pbuff,
                cbuff, pathbuff, &dwpathbufflen);
            if (INSTALLSTATE_LOCAL==ival)
            {
                 // starts with a zero - it's a registry key 
                if (memcmp (pathbuff, "0", 1) ==0)
                {
                    char regname [MAX_PATH] = {0};
                    switch (pathbuff[1]) 
                    {
                    case '0': strcpy (regname, "HKCR"); break;
                    case '1': strcpy (regname, "HKCU"); break;
                    case '2': strcpy (regname, "HKLM"); break;
                    case '3': strcpy (regname, "HKUSERS"); break;
                    }
                    strcat (regname, pathbuff+3);
                    strcpy (pathbuff, regname);
                }

                fprintf(listdata, "Component %s installed at %s\n",
                        cbuff, pathbuff);
            }
        }


    }
    return 0;
}
//End of File
Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK