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