The only way to obtain a Bad Egg is by hacking, or cheating.
In Generation III, a Bad Egg will appear if you are using a Gameshark code for quick leveling up in the Daycare, where an invisible Bad Egg will appear in your party. If you view it's game Summary, the game will freeze.
You can also obtain a Bad Egg by using codes to capture Pokemon instantly, where when you catch the Pokemon, they will be sent to your PC as a Bad Egg.
You can also obtain a Bad Egg by making Pokemon have illegal movesets, like a Magikarp with Hyper Beam.
In Generation IV, the game will most likely freeze if you see a Bad Egg, and you obtain it of course through hacking.
For more information on Bad Eggs, visit Bulbapedia.