I manage Windows Server 2016 instances from a Windows 10 Pro desktop using Remote Desktop Connection. When I restart a server, the remote desktop connection closes and I have to ping the machine until I know it's back up and ready to reconnect again.

Can I have Remote Desktop Connection do this for me? All I'm expecting to happen is that the window would stay open and periodically try to reconnect every few seconds until a connection is reestablished.


As far as I know this is not possible. There is an Auto-reconnect param in RDP but that works only when the connection was dropped due to network issues and such but the disconnected RDP session itself is still available on the server. When you restart the server via RDP the session will close down fully and therefore the client "knows" that there isn't any session for it on the server.

A possible workaround is to write a simple script for this scenario. Like in Powershell:

While($i -ne 1) {
    Start-Process -FilePath "test.rdp" -Wait;

This restarts the RDP connection (more precisely it starts a completely new one) after it's closed until you stop the script (pressing Ctrl+C or clicking on the Stop button in Powershell ISE).

You can combine it with a network ping before actually starting the RDP connection and some output to know what's happening at a given moment.

Try {
    Write-Host "Press CTRL+C to stop the script.";
    While($i -ne 1) {
        Write-Host "Pinging server...";
        If (Test-Connection -ComputerName rdp-server.local -Count 1 -ErrorAction SilentlyContinue) {
            Write-Host "Ping OK. Starting RDP connection...";
            Start-Process -FilePath "test.rdp" -Wait;
            Write-Host "RDP connection closed. Restarting...";
        } Else {
            Write-Host "Ping failed. Retry...";
} Finally {
    Write-Host "CTRL+C pressed. Bye!";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.