We start with the given limit:
\[
\lim_{x \to \infty} \left( 1 + \frac{a}{x} + \frac{b}{x^2} \right)^{2x} = e^2
\]
We can rewrite this as:
\[
\lim_{x \to \infty} \left( 1 + \frac{a}{x} \right)^{2x} \times \lim_{x \to \infty} \left( 1 + \frac{b}{x^2} \right)^{2x}
\]
The first limit is well known:
\[
\lim_{x \to \infty} \left( 1 + \frac{a}{x} \right)^{2x} = e^{2a}
\]
For the second term, since \( b/x^2 \to 0 \) as \( x \to \infty \), we have:
\[
\lim_{x \to \infty} \left( 1 + \frac{b}{x^2} \right)^{2x} = 1
\]
Therefore, the limit is:
\[
e^{2a} \times 1 = e^2
\]
Thus, \( 2a = 2 \), so \( a = 1 \).
The value of \( b \) can be any real number because it does not affect the limit.