We want to run a script when user tries to disconnect a remote session (using Remote Desktop) by clicking the "X (close)" button. Any help on the event that gets triggered on clicking "X/close" button in remote session would also help us. The Script should run before the disconnection is complete. Basically when the system prompts user for confirmation of disconnection. We are using Windows Server 2016.
I dont believe this is possible. Hitting the X is closing the application. The user's Remote Desktop application warns the user that this will end the session, but all this is done client side. There is no way for the remote server to know the session is disconnected till it happens and therefore, you couldnt run a script in that manner.