0

I have 2 programs in the RDP -- 1)A.bat & 2)B.exe

Execution process of A.bat is something like -

Step1: Download a file from internet using the command --

powershell -c "Invoke-WebRequest -Uri 'https://laptop-updates.brave.com/latest/winx64' -OutFile 'C:\Users\Administrator\Desktop\B.exe'"

Step2: Modify a RegistryKey so that B.exe can run automatically in the next reboot. Command used for that purpose--

reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v runonce /t REG_SZ /d "C:\Users\Administrator\Desktop\B.exe" /f

Step3(Last step): Reboots the RDP. Command used--

shutdown /r /t 0

Execution process of B.exe is not our concern. My problem is when A.bat executes the last command the RDP session closes and returns me to my local pc. RDP takes some time to fully wake up. After waking up it doesn't automatically login to it's desktop. Again i have to login manually to the RDP using Remote Desktop Connection so that B.exe can run. I just want that after reboot, RDP automatically login to the desktop causing B.exe to run in the startup.

N.B: Using Windows Server 2019 in Amazon EC2 instance as RDP.

2 Answers2

1

RDP will not login automatically just because the server on the other side has rebooted. The most you can do is write a script that you can run on your side to do the logon, so as to make it easier to start the remote session.

You may save in RDP the connection details to a .rdp file, specifying fully the parameters for the connection, window size, shared devices and more.

To launch the .rdp file, use the mstsc command:

mstsc path\connection-file.rdp

You may put the command in a .bat file, or as a desktop icon, to restart the remote session with one double-click.

harrymc
  • 498,455
0

Without knowing exactly what b.exe is, it is hard to suggest the proper strategy here.

But that said, when a remote server reboots, RDP will obviously always disconnect. There is nothing you can do, and given that boot times are different, there is no easy way to automatically reconnect after the connection is ready again.

That said, it is usually not the right approach to want to login to a server just so a program can start.

The right way to do it, is turn that program into a service, such that if the server reboots, the server just starts automatically and no one even needs to be logged in.

There are different programs (free) out there that can turn any program into a service. Process Hacker 2 (taskmanager replacement) is one of them, but there are more. I believe Microsoft's SysInternals have a program that can do it too.

So, if you want B.exe to always run after startup, turn it into a service. You can even create a service from the command prompt. The only requirement for a service is, that you are working with a .exe file, but that is what you have.

LPChip
  • 66,193