First the equations for all vectors $x$ on line $g$ and all vectors $y$ on line $h$:
$$
\begin{align}
g: x &= a + \lambda b \quad \\
h: y &= c + \mu d
\end{align}
\quad (*)
$$
The difference vector between two of those vectors is
$$
D = y - x = c - a + \mu d - \lambda b
$$
The length of $D$ squared is:
\begin{align}
q(\lambda, \mu)
&= D \cdot D \\
&= (c - a)^2 + (\mu d-\lambda b)^2 + 2 (c-a)\cdot(\mu d - \lambda b) \\
&= (c - a)^2 + \mu^2 d^2 + \lambda^2 b^2 - 2 \mu \lambda (d\cdot b)
+ 2 \mu ((c-a)\cdot d) - 2 \lambda ((c-a)\cdot b) \\
\end{align}
The gradient of $q$ is:
$$
q_\lambda = 2\lambda b^2 - 2\mu (d\cdot b)-2((c-a)\cdot b) \\
q_\mu = 2\mu d^2 - 2\lambda (d\cdot b)+2((c-a)\cdot d)
$$
It should vanish for local extrema of $q$ which leads to the system
$$
A u = v
$$
with
$$
A =
\left(
\begin{matrix}
b^2 & - d\cdot b \\
- d \cdot b & d^2
\end{matrix}
\right)
\quad
u =
\left(
\begin{matrix}
\lambda \\
\mu
\end{matrix}
\right)
\quad
v =
\left(
\begin{matrix}
(c-a) \cdot b \\
-(c-a) \cdot d
\end{matrix}
\right)
$$
A unique solution exists for
$$
0 \ne \mbox{det A} = b^2 d^2 - (d \cdot b)^2
$$
Note that the dot operator stands for the scalar product.
That solution is
$$
u = A^{-1} v
$$
with
$$
A^{-1} = \frac{1}{\mbox{det } A}
\left(
\begin{matrix}
d^2 & d\cdot b \\
d \cdot b & b^2
\end{matrix}
\right)
$$
Inserting the found values for $\lambda$ and $\mu$ into equations $(*)$ will provide you the two vectors, whose points are closest to each other.
Example:
$$
a = (2,0,0), b=(1,1,1), c=(0,1,-1), d=(-1,0,-1)
$$
leads to
$$
\lambda = 1, \mu = -2.5, x_\min = (3,1,1), y_\min=(2.5,1,1.5), D=(-0.5,0,0.5)
$$
The image renders the $x$ values in green, the $y$ values in purple, and $D$ in red.
Let $z=t$.
Hence, $x+y=3-2t$ and $2x+3y=4-4t$, which gives $x=5-2t$ and $y=-2$.
Thus, $(5-2t,-2,t)$ is our line.
Now, let $(5-2t,-2,t)\subset\pi$ and $(0,0,k)||\pi$.
Let $\vec{n}(a,b,c)$ is a normal of $\pi$.
Thus, $(a,b,c)(0,0,1)=0$ and $(a,b,c)(-2,0,1)=0$ or $c=0$ and $-2a+c=0$,
which gives that $\vec{n}(0,1,0)$ and the equation of $\pi$ it's
$y=-2$.
Id est, the distance is $2$.
Best Answer
$$L_1: \frac{x+2}{2}=\frac{y+6}{3}=\frac{z-34}{-10}=a$$
On $L_1$, a general point is $\vec p_1=(2a-2,3b-6,-10a+34)$
$$L_2: \frac{x+6}{4}=\frac{x-7}{-3}=\frac{x-7}{-2}=b$$ A generat point on $L_2$ is $\vec p_2\ (4b-6,-3b+7,-2b+7)$ Let the line $L_3$ which is $P_1P_2$, intersects both $L_1$ and $L_2$ orthogonally, then $$(\vec p_1- \vec P_2).\vec L_1 =0 = (\vec P_1- \vec P_2). \vec L_2$$ We get $$113a-19b=301,~~ 19a-29b=-1 \implies a=3, b=2$$ So the point $\vec P_1=(4,3,4), \vec P_2=(2,1,3)$ We get line $L_3$ which joins $P_1,P_2$ as $$L_3: \frac{x-4}{2}=\frac{y-3}{2}=\frac{z-4}{1}=c$$ with a gereral point $\vec p=(2c+4,2c+3, c+4)$ on it. Then $\vec {OP}$ is perpendicular to $L_3$, so we get $2(2c+4)+2(2c+3)+1(c+4)=0 \implies c=-2$ giving us the foot of perpendicular as $(0,-1,2)$, its distance from orogin is $\sqrt{5}$ which is the required distance.