This is not true. Morally, the right hand side corresponds to the functions that are regular at all $\mathfrak p_i$, and one can show that this is not always a localisation of the entire ring $A$.

**Example.** Let $(E,O)$ be an elliptic curve over an algebraically closed field $k$, and let $P \in E(k)$ be a non-torsion point. Let $X = E \setminus \{O\}$, and $U = X \setminus\{P\}$. Then $X$ and $U$ are affine, and $U$ is not a principal affine open of $X$ (see e.g. this post).

If $X = \operatorname{Spec} A$, then $P$ corresponds to a prime $\mathfrak p \subseteq A$. We consider the intersection
$$\bigcap_{\mathfrak q \neq \mathfrak p} A_\mathfrak q \subseteq \operatorname{Frac} A$$
and the set
$$S = A \setminus \bigcup_{\mathfrak q \neq \mathfrak p} \mathfrak q.$$
(In either case, it doesn't matter whether we include the zero ideal as well or only the maximal ideals.)
We claim that $S = A^\times$. Indeed, clearly $A^\times \subseteq S$. Conversely, suppose $f \in A$ is not in $A^\times$. Then $V(f)$ contains a point $Q \neq P$, hence $f$ is contained in a prime $\mathfrak q \neq \mathfrak p$. Thus, $f \not \in S$.

This proves that $S = A^\times$, and therefore $S^{-1}A$ is just $A$. But if $B = \Gamma(U,\mathcal O_U)$, then
$$\bigcap_{\mathfrak q \neq \mathfrak p} A_{\mathfrak q} = \bigcap_{\mathfrak r \in \operatorname{Spec} B} B_{\mathfrak r} = \Gamma(U,\mathcal O_U),$$
which cannot be equal to $A$ because $X \not \cong U$. $\square$