Typically you use a pawn storm to exchange pawns around the castled enemy king and thereby to open lines and diagonals for an attack. Most of the time you want a closed (to some extent) center in order to avoid counterplay in the center.
In this sense your example 4 is not a typical use case for a pawn storm. It might make sense to push the pawns here as well, but the reason for that are concrete tactical motifs. E.g. by playing g4-g5 you seem to force black to exchange the bishop for the knight after which there are ideas with Qg7 mate...
Other than that, it depends a lot on the actual position.
A typical defensive strategy is to block the advancing pawns, thereby halting the pawn storm. In your first example you need to consider that if you play g5 black can block with h5, if you play h5, black can block with g5. To break such blockades, you could consider piece sacrifices (for a pawn or two) or what options you have by pushing the f pawn.
In your second example, if you play g5, black can block with Nh5. In your third example, playing first g4 leaves you with lots of weak dark squares that are eyed by the black queen and knight. Playing first h4 here seems like a much better choice (if you had to decide between g4 or h4).
Some general guidelines (but as mentioned above, don't follow these blindly) depending on the opponent's pawn structure (of course the same applies to exchanged colors):
Pawns on f7-g7-h7
- typically broken by playing g6 supported by a pawn from h5. See English attack in the Najdorf Sicilian.
- You could also attack with h6, but this really only makes sense if you can make use of the dark squares, e.g. if you have a queen, dark squared bishop... that can enter via the a1-h8 diagonal or if you have a knight that could use the outpost that forms on f6.
Pawns on f7-g6-h7
- Break with h5. Most of the time you want rooks on the h-file for the attack, when the h-file opens. See Yugoslav attack in the Sicilian Dragon.
- Need to consider whether black can close the position with g5 after you play h5. Therefore in some cases, white wants to play g5 before h5.
Pawns on f7-g6-h6
- This is a flexible setup for black, because whether you play h5 or g5, black can always block replying g5 or h5 respectively.
- One idea to break it is with a pawn on f4, so as white you aim for h5 but have a pawn on f4 (ready or can play later) in order to prevent the blocking with g5.
- Another idea to break it is tactically. Often you end up with such positions, like in your first example, with Qd2, Be3 and Kh7. A typical tactical idea then is to play Ng5 with a white pawn on h4 and a rook on h1. If black takes the pawn hxg5, white opens the h-file with hxg5 check which very often is deadly.
Pawns on f6-g7-h7
- You'd go for the f6 pawn by playing g5. Need to consider, whehter black can reply with f5 after which there is not much of an attack.
- Sometimes you could follow up with h5-h6 with the idea that the g7 pawn moves and cannot recapture on f6.
- See attacks against the Sämisch in the Kings Indian. (i.e. pawn storm by black)
As mentioned these don't work all the time and depend on the concrete position. If you consider the potential for blocking the pawn advance, by closing the structure, which pawn to push often comes naturally.
I'd recommend to look at some of these attacks in actual games. You can use the openings mentioned above as a guideline.