How can I farm the Cows?
If anyone kills Cow King for FIRST time (except, a person who has NOT killed Baal/Diablo, see below), then everyone INSIDE the Cow Level will get credit for the (hidden) Cow King quest and will NOT make the red portal anymore. If you don't want to complete the Cow King quest or are unsure, the safest place to be is in town (use Town Portal scroll!). Unpartying will do you no good. Watch your Mercenary and Summons as they can "accidentally" kill him, too.
However, if you do not kill Baal (or Diablo, if you don't have the expansion) on that difficulty you will be unable to make the red portal, but you will never get credit for the quest to kill the Cow King (because you need to have killed Baal/Diablo to be able to start the quest). If this character kills the Cow King, everyone in the Cow Level who could make the red portal will still be able to open the portal.
Any character who has previously killed the Cow King (can't open the red portal) can kill him again without affecting people who have not yet killed him (can open red portal).
Alternatively, you can have one character (who's killed Baal/Diablo on that difficulty) make the portal, log out and then log in onto another character (who has NOT killed Baal/Diablo on that difficulty) you want to farm the Cows on.
Side note: The Cow King is Lightning Immune on ALL difficulties So if you are Lightning Fury Amazon or a Nova Sorceress, you can avoid killing the Cow King by using Lightning skills (if you don't use a Mercenary or Valkyrie). The Cow King will always drop 8 stamina potions when he dies, you can (usually) use this as an indicator of whether or not it's safe to (blindly) murder all the other cows.
Here's the official source. MOO.
The safest way is to leave the game whenever you contact the Cow King. Sometimes it'll be unlucky and you'll find him immediately, but most of the time you won't find him until you've killed plenty of other cows.
It's not a very big investment to open the portal, so leaving the game whenever the Cow King presents himself is not going to set you back. The one run that you leave immediately will be compensated for from the gold you get in the other runs where you kill a bunch of cows.
The easiest way to identify the Cow King is that he is always lightning enchanted, so if you see any sparks flying off any cows, get out of there.
As for battle.net, if you really want to be safe about it, you have to make sure you're playing alone. If any player in the game kills the Cow King, that ruins it for you. Unless you can fully trust those you're playing with, don't risk it if repeating this level is important for you. No other adjustments are necessary, really.