If this occurs while installing any expansion packs, then first uninstall that by using "Add or Remove Programs" in the Control Panel. Once you did that, also remove all files from the installation directory. By default that is C:\Program Files\Maxis\The Sims. You can do that by using Explorer (My Computer), and browse to that folder where you installed The Sims, and delete all the remaining files.
Next, run SimEraser. This can be found on the CDs of Unleashed, Superstar and Makin' Magic. Use the edition on the latest expansion pack you own. If you don't have any of those, you can download it from this page
at the official site.
After that, you should be able to install The Sims and all expansion packs again without any problems.