wsprintf(szKey, "Software\\Mozilla\\%s %s", szCleanupProduct, szUAShort); DeleteWinRegKey(hkeyRoot, szKey, TRUE);
void CleanupPreviousVersionRegKeys(void){  DWORD dwIndex = 0;  DWORD dwSubKeyCount;  char  szBufTiny[MAX_BUF_TINY];  char  szKeyRoot[MAX_BUF_TINY];  char  szCurrentVersion[MAX_BUF_TINY];  char  szUAShort[MAX_BUF_TINY];  char  szRvSubKey[MAX_PATH + 1];  char  szPath[MAX_BUF];  char  szKey[MAX_BUF];  char  szCleanupProduct[MAX_BUF];  HKEY  hkeyRoot;  char  szSubSubKey[] = "Main";  char  szName[] = "Install Directory";  char  szWRMSUninstall[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";  char  szSection[] = "Cleanup Previous Product RegKeys";  lstrcpy(szPath, sgProduct.szPath);  if(*sgProduct.szSubPath != '\0')  {    AppendBackSlash(szPath, sizeof(szPath));    lstrcat(szPath, sgProduct.szSubPath);  }  AppendBackSlash(szPath, sizeof(szPath));  wsprintf(szBufTiny, "Product Reg Key%d", dwIndex);          GetConfigIniProfileString(szSection, szBufTiny, "", szKey, sizeof(szKey));  while(*szKey != '\0')  {    wsprintf(szBufTiny, "Reg Key Root%d",dwIndex);    GetConfigIniProfileString(szSection, szBufTiny, "", szKeyRoot, sizeof(szKeyRoot));    hkeyRoot = ParseRootKey(szKeyRoot);    wsprintf(szBufTiny, "Product Name%d", dwIndex);            GetConfigIniProfileString(szSection, szBufTiny, "", szCleanupProduct, sizeof(szCleanupProduct));    // something is wrong, they didn't give a product name.    if(*szCleanupProduct == '\0')      return;    wsprintf(szBufTiny, "Current Version%d", dwIndex);            GetConfigIniProfileString(szSection, szBufTiny, "", szCurrentVersion, sizeof(szCurrentVersion));    do    {      // if the current version is not found, we'll get null in szCurrentVersion and GetWinRegSubKeyProductPath() will do the right thing      dwSubKeyCount = GetWinRegSubKeyProductPath(hkeyRoot, szKey, szRvSubKey, sizeof(szRvSubKey), szSubSubKey, szName, szPath, szCurrentVersion);  	        if(*szRvSubKey != '\0')      {        if(dwSubKeyCount > 1)        {          AppendBackSlash(szKey, sizeof(szKey));          lstrcat(szKey, szRvSubKey);        }        DeleteWinRegKey(hkeyRoot, szKey, TRUE);        GetUserAgentShort(szRvSubKey, szUAShort, sizeof(szUAShort));        if(*szUAShort != '\0')        {          /* delete uninstall key that contains product name and its user agent in parenthesis, for           * example:           *     Mozilla (0.8)           */          wsprintf(szKey, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s (%s)", szCleanupProduct, szUAShort);          DeleteWinRegKey(hkeyRoot, szKey, TRUE);          /* delete uninstall key that contains product name and its user agent not in parenthesis,           * for example:           *     Mozilla 0.8           */          wsprintf(szKey, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s %s", szCleanupProduct, szUAShort);          DeleteWinRegKey(hkeyRoot, szKey, TRUE);          /* We are not looking to delete just the product name key, for example:           *     Mozilla           *           * because it might have just been created by the current installation process, so           * deleting this would be a "Bad Thing" (TM).  Besides, we shouldn't be deleting the           * CurrentVersion key that might have just gotten created because GetWinRegSubKeyProductPath()           * will not return the CurrentVersion key.           */        }        // the szKey was stepped on.  Reget it.        wsprintf(szBufTiny, "Product Reg Key%d", dwIndex);                GetConfigIniProfileString(szSection, szBufTiny, "", szKey, sizeof(szKey));      }    }  while (*szRvSubKey != '\0');    wsprintf(szBufTiny, "Product Reg Key%d", ++dwIndex);            GetConfigIniProfileString(szSection, szBufTiny, "", szKey, sizeof(szKey));  } }