why do you need this? Might be that if you will explain it, we could provide you better solution. Note also that on 3rd it will not work.
Anyway you can try the RApaLsSession class to enumerate all installed applications(note that I did not test the code):
TInt err = KErrNone;
err = ls.GetNextApp(appInfo);
if (KErrNone == err && appInfo.iCaption.Length())
} while(KErrNone == err);
CleanupStack::PopAndDestroy(); // ls