  Using scanning tunneling microscopy and spectroscopy we investigate the
adsorption properties and ring-closing reaction of a diarylethene derivative
(C5F-4Py) on a Ag(111) surface. We identify an electron-induced reaction
mechanism, with a quantum yield varying from $10^{-14}-10^{-9}$ per electron
upon variation of the bias voltage from $1-2$ V. We ascribe the drastic
increase in switching efficiency to a resonant enhancement upon tunneling
through molecular orbitals. Additionally, we resolve the ring-closing reaction
even in the absence of a current passing through the molecule. In this case the
electric-field can modify the reaction barrier, leading to a finite switching
probability at 4.8 K. A detailed analysis of the switching events shows that a
simple plate-capacitor model for the tip-surface junction is insufficient to
explain the distance dependence of the switching voltage. Instead, describing
the tip as a sphere is in agreement with the findings. We resolve small
differences in the adsorption configuration of the closed isomer, when
comparing the electron- and field-induced switching product.
