Hello,
With RDP, it is a known issue with any automation software that when you minimize or close the window, macro doesn't run. However, you can solve this using VNC. You can keep the VNC session minimized or closed and the automated task would work as expected.
You can find VNC software from the following link:
RealVNC - Download VNC software
Hope that helps.