Yes: Let $(f,\psi):X\to Y$ be a morphism of locally ringed spaces, where $X$ and $Y$ are smooth manifolds with their sheaves of smooth functions. If $\psi:C^\infty_Y \to f_* C^\infty_X$ is a morphism of sheaves of $\mathbb R$-algebras, then $f$ is smooth and $\psi=f^\#$.
Proof. Let $s:U\to \mathbb R$ be a smooth function. The equation $\psi s= s\circ f$ follows from the commutativity of the diagram below. Notice the triangle commutes because there is a unique $\mathbb R$-algebra map $C^\infty_{f(x)}/{\frak m}_{f(x)}\cong \mathbb R \to \mathbb R$. It now follows that $f:X\to Y$ is smooth. Indeed, we know $s\circ f$ is smooth for all real valued functions $s$ on $Y$, and we may take $s$ to be the coordinate functions of charts on $Y$. QED.
This is a riff on the more general question "what is the universal property of associated graded?" I won't discuss the rings-and-ideals case at all, and will just restrict my attention to filtered vector spaces.
Classically a filtered vector space is an increasing sequence $V_0 \subseteq V_1 \subseteq V_2 \subseteq \dots $ and it has an associated graded vector space given in degree $i$ by $V_i/V_{i-1}$. One of the first MO questions (#263!) asked whether this functor is a left or a right adjoint, and the answer is that it is neither.
This turns out, however, to be an artifact of working with an insufficiently flexible notion of filtration; it turns out that requiring all the maps $V_i \to V_{i+1}$ to be inclusions is too restrictive and makes the category behave poorly, and we can fix this by working with a generalized notion of filtration given just by a sequence $V_0 \to V_1 \to V_2 \to \dots$ of not-necessarily-injective maps. With this fix, as described by Nicholas Schmidt, taking associated graded is left adjoint to the functor which sends a graded vector space $W_i$ to the sequence $W_0 \xrightarrow{0} W_1 \xrightarrow{0} W_2 \dots$ where all maps are zero, and in particular it now preserves colimits (which behave differently and better in this new category of filtered vector spaces).
There is a lovely algebro-geometric interpretation of a further generalization of this construction where we allow $\mathbb{Z}$-gradings, as follows. The category of $\mathbb{Z}$-graded vector spaces can be identified with the category of quasicoherent sheaves over the stack $B \mathbb{G}_m$ which classifies line bundles; this is a fancy way of saying that an action of $\mathbb{G}_m$ is the same thing as a $\mathbb{Z}$-grading. The category of "$\mathbb{Z}$-filtered" vector spaces, by which I mean sequences $\dots V_i \to V_{i+1} \dots$ possibly extending infinitely in both directions, can in turn be identified with the category of quasicoherent sheaves over the quotient stack $\mathbb{A}^1/\mathbb{G}_m$. There is a natural inclusion
$$i : B \mathbb{G}_m \to \mathbb{A}^1/\mathbb{G}_m$$
given by thinking of $B \mathbb{G}_m$ as $\bullet / \mathbb{G}_m$ and including $\bullet$ into $\mathbb{A}^1$ as the origin, and the associated graded functor turns out to be the pullback $i^{\ast}$ of quasicoherent sheaves along $i$, left adjoint to pushforward $i_{\ast}$.
Best Answer
The $Spec$ functor is the desired adjoint functor to the category of locally ringed spaces (it is right adjoint to $\Gamma$). I think Hartshorne has an exercise where he asks us to prove this when $Loc$ is replaced by the category of schemes.
I like Anton Geraschenko's answer here: https://mathoverflow.net/questions/731/points-in-algebraic-geometry-why-shift-from-m-spec-to-spec/756#756