There are two ways to approach this;
1. Place your pointer finger on the B note (second fret of the A string,) and barre with your third finger on the D, G, and B strings on the fourth fret. I tend to play major barre chords this way, although I know if this is a new shape it may be a little tricky. See if you can get all three notes to come out with just your ring finger and if not, try the next suggestion.
2. This seems to be the most common way, and reflective of your question. You play B with your first finger on the second fret of the A string, F# on the fourth fret of the D string with your ring finger, and B again on the fourth fret of the G string.
The G string isn't played at all and to mute that, you wanna just lightly press on it with your first finger utilizing the area of your finger between your top and between joints. That area, when applied gently, does a great job of muting these strings.
This can be tricky, but again rest assured every conquest leads to another discovery and once you can play a B chord correctly; you can play major barre chords up and down the neck all day and play all kinds of songs and chords.
Best of luck and hopefully this helps!
- Douglas
Douglas Showalter