BOOL CALLBACK EnumAvailableAppProc(APPLICATION_INFO Info) { PAPPLICATION_INFO ItemInfo; INT Index; /* Only add a ListView entry if... - no RegName was supplied (so we cannot determine whether the application is installed or not) or - a RegName was supplied and the application is not installed */ if (!*Info.szRegName || (!IsInstalledApplication(Info.szRegName, FALSE) && !IsInstalledApplication(Info.szRegName, TRUE))) { ItemInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(APPLICATION_INFO)); if (!ItemInfo) return FALSE; *ItemInfo = Info; Index = ListViewAddItem(Info.Category, 0, Info.szName, (LPARAM)ItemInfo); ListView_SetItemText(hListView, Index, 1, Info.szVersion); ListView_SetItemText(hListView, Index, 2, Info.szDesc); } return TRUE; }
BOOL CALLBACK EnumAvailableAppProc(PAPPLICATION_INFO Info) { INT Index; if (!SearchPatternMatch(Info->szName, szSearchPattern) && !SearchPatternMatch(Info->szDesc, szSearchPattern)) { return TRUE; } /* Only add a ListView entry if... - no RegName was supplied (so we cannot determine whether the application is installed or not) or - a RegName was supplied and the application is not installed */ if (!*Info->szRegName || (!IsInstalledApplication(Info->szRegName, FALSE) && !IsInstalledApplication(Info->szRegName, TRUE))) { Index = ListViewAddItem(Info->Category, 0, Info->szName, (LPARAM)Info); ListView_SetItemText(hListView, Index, 1, Info->szVersion); ListView_SetItemText(hListView, Index, 2, Info->szDesc); } return TRUE; }
// // ScanWindowsInstaller // ==================== // // Scan the Windows installer registry key for installed applications not detected previously // void CApplicationInstanceList::ScanWindowsInstaller(HKEY rootKey) { char szBuffer[REG_BUFFER_SIZE]; DWORD dwLength = REG_BUFFER_SIZE; DWORD dwIndex = 0; // Enumerate the sub-keys beneath the Windows installer while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx (rootKey, dwIndex, szBuffer, &dwLength, NULL, NULL, NULL, NULL)) { // prepare to get next key dwIndex++; dwLength = REG_BUFFER_SIZE; CString subKeyName = szBuffer; CLogFile log; // Open the Install Features sub-key CString productKey; productKey.Format("%s\\%s" ,WINDOWS_INSTALLERKEY ,subKeyName); HKEY hProductKey; if (RegOpenKeyEx (rootKey, subKeyName, 0, KEY_READ, &hProductKey) == ERROR_SUCCESS) { // Is this a valid installed application? if (IsInstalledApplication(rootKey ,subKeyName)) { CString applicationName = GetApplicationName(rootKey ,subKeyName, (CString)DISPLAYNAME); CString version = CReg::GetItemString(rootKey ,subKeyName ,DISPLAYVERSION); CString publisher = CReg::GetItemString(rootKey ,subKeyName ,PUBLISHER); publisher = RationalizePublisher(publisher); // Recover (any) product ID / Serial Number specified for the application CString productID = CReg::GetItemString(rootKey ,subKeyName ,PRODUCTID); if (productID.IsEmpty()) productID = CReg::GetItemString(rootKey ,subKeyName ,SERIALNUMBER); // Format the product GUID from the sub-key name CString productGUID = subKeyName.Mid(0, 8) + "-" + subKeyName.Mid(8, 4) + "-" + subKeyName.Mid(12, 4) + "-" + subKeyName.Mid(0x10, 4) + "-" + subKeyName.Mid(20, 8); // Add this instance to our internal list AddApplicationInstance(applicationName, publisher, productGUID, productID, version); } RegCloseKey(hProductKey); } } }
// // ScanUninstallKey // ================ // // Scan the UNINSTALL registry key beneath the supplied registry hive lookimg for applications that // have been installed. // void CApplicationInstanceList::ScanUninstallKey(HKEY hKey) { char szBuffer[REG_BUFFER_SIZE]; DWORD dwLength = REG_BUFFER_SIZE; DWORD dwIndex = 0; // Enumerate the sub-keys while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx (hKey, dwIndex, szBuffer, &dwLength, NULL, NULL, NULL, NULL)) { // prepare to get next key dwIndex++; dwLength = REG_BUFFER_SIZE; // Is this an installed application? CString subKeyName = szBuffer; if (IsInstalledApplication(hKey ,subKeyName)) { CString displayName = GetApplicationName(hKey ,subKeyName, (CString)DISPLAYNAME); CString productGUID = ""; // Is the sub-key name a GUID - if so recover the GUID as this can be used to find a serial number if (subKeyName[0] == '{' && subKeyName[subKeyName.GetLength() - 1] == '}') productGUID = subKeyName.Mid(1, subKeyName.GetLength() - 2); // Recover other attributes for the application CString version = CReg::GetItemString(hKey ,subKeyName ,DISPLAYVERSION); CString publisher = CReg::GetItemString(hKey ,subKeyName ,PUBLISHER); publisher = RationalizePublisher(publisher); // Recover (any) product ID / Serial Number specified for the application CString productID = CReg::GetItemString(hKey ,subKeyName ,PRODUCTID); if (productID.IsEmpty()) productID = CReg::GetItemString(hKey ,subKeyName ,SERIALNUMBER); // Add this instance to our internal list AddApplicationInstance(displayName, publisher, productGUID, productID, version); } } }