If there is a ranger or a druid or something that has an animal companion/familiar/equivalent, and a player tries to attempt an Handle Animal check to get it to do what they want, would it be an automatic fail or what should I do in this situation?
A creature that attempts to employ on a familiar the skill Handle Animal in an effort to have the familiar perform a trick will fail. The typical familiar's Intelligence score is just too high for it to be handled in such a way.
A creature that attempts to employ on the typical animal companion the skill Handle Animal in an effort to have the animal companion perform a trick may succeed. The creature can take a move action to pick a trick and make a Handle Animal skill check to handle the animal (DC 15). Success means that the animal performs the trick if it knows it. Failure means it doesn't.
Alternatively, the creature can take a full-round action to pick a trick and make a Handle Animal skill check to "push" the animal (DC 25). Success means that the animal performs the trick. Failure means it doesn't.
However, whether the creature has the opportunity to make either check is contingent upon the animal's attitude toward the potential handler: the extraordinary ability wild empathy (PH 47-8), in part, says, "The typical domestic animal has a starting attitude of indifferent, while wild animals are usually unfriendly." Since a creature with no ranks in the skill Handle Animal can make Handle Animal skill checks against domesticated animals by making, instead, Charisma ability checks, presumably, indifferent is sufficient to boss around a stray housecat, milking goat, or sheepdog, but this DM would prohibit a creature from attempting Handle Animal skill checks to boss around wild—therefore typically unfriendly—animals, including, perhaps, some of those available to even a starting druid, like the badger, crocodile, squid, viper, and wolf.
Also, note that this DM doesn't allow another creature to, essentially, seize control of an animal companion in combat. Instead, this DM has the animal companion have a hostile attitude toward its master's foes, allowing the animal companion to ignore enemies' attempts at handling it.
The person trying to use the trick with Handle Animal spends a standard action to activate the trick while the druid/ranger can spend a free action to command it. So it's only good once the master has been defeated, you send it's companion "home".