Actually, if the electrical installation at home or office meet the standard, which are equipped with electric grounding (has connection to the ground/earth), this electric shock can be avoided.
If your electric source for your computer has no electrical grounding, and you get electric shock when touching the CPU case, for quick solution and easy way, you can make simple grounding. using nail and electric single cable.
Peel the end of the cable and wrap it around the nail.
Peel the other end of the cable and wrap it to one of the screws at back computer body/case.
(Beforehand loosen the screw using a screwdriver, and afterwards tighten again)
Plug nails into the ground.