denote the equations of the two lines. I assume that and that exist
To calculate the endpoints of the shortest distance between arbitrary points of the two lines the distance vector must be a multiple of the normal vector:
You'll get a system of 3 simultaneous equations. Solve for (s, t, k). Plug in the values of s and t into the appropriate equations to get the endpoints of the distance.