The baby's gender is determined at the moment of conception, depending on whether a male or female sperm fertilises the egg.
Ultrasound can tell from around 16 weeks, as this is when the relevant bits are formed enough to tell which sex it is. CVS can identify the gender, but I don't think it is done solely for this purpose, commercially or otherwise because it is an invasive process that carries some degree of risk (they take a cell sample from the placenta I think)
If you need a CVS for other purposes (eg identified as high risk of downs or some kind of congenital abnormality) they will also tell you the gender should you so wish, which is how people can sometimes find out earlier than the ultrasound can tell, but as far as I'm aware, it's not used solely as a way of determining the gender.