Systems defined by $dx(t) = a\lbrack x(t), t \rbrack dt + B\lbrack x(t), t \rbrack u(t) dt + N^{1/2}\lbrack x(t), t \rbrack dW(t)$, where $x(t)$ is the state variable, $u(t)$ is the control variable, $a$ is a vector function, $B$ and $N$ are matrices and $W(t)$ is a Brownian motion process, are considered. The aim is to minimize the expected value of a cost function with quadratic control costs on the way and terminal cost function $K(T)$, where $T = \inf\{s: x(s) \in D \mid x(t) = x\}, D$ being a given region in $\mathbb{R}^n$. The function $K$ is taken to be 0 if $T \geq (\leq) \tau$, where $\tau$ is a positive constant and $+\infty$ if $T < (>) \tau$ when the aim is to force $x(t)$ to stay in (resp., to leave) the region $C$, the complement of $D$. A particular one-dimensional problem is solved explicitly and a risk-sensitive version of the general problem is also considered.