The Squeaks are usually caused by a floor joist under the decking (plywood flooring) being misnailed. As the plywood flooring is going down the person doing the nailing simply drifted right or left slightly and missed or came very close to missing the joist with his/her nail. As the floor takes weight the loose nails ride up and down a little causing the squeak. Another problem in newer homes is the staples they are using instead of nails. Usually put down with a gun and nails can be too the old school way of feeling the nail drive into solid wood is no longer an option thus allowing for misses more often.
For carpet they make a kit where the new nail or stud goes through the flooring from the top down into the floor joist and the top exposed part snaps off but you STILL have to locate the joist underneath and HIT it for this to work. If it were me doing the repairs in my house, I would just simply get out the nails and drive them down through the carpet and use a nail set to push them deep into the nap of the carpet and out of sight. You want to make sure you don't get carpet tucked underneath the nail head prior to seating it though or you'll see the nail head.
Hardwood floors are a different story... you will either need to pull the hardwood and deal with it or take care of it from underneath... same with tile flooring or vinyl flooring found in bathrooms.