You have to define that a certain task has to be executed on the remote PC when you terminate the Remote Desktop session. I prefer to run a simple batch file on the remote computer under certain conditions (see below). This batch file uses the command line tool 'klocks.exe':
klocks.exe -scroll +num -c
This line just activates the NUMLOCK state (and deactivates the SCROLL and the CAPSLOCK state). Unfortunately I noticed that the original download site is not available anymore (http://www.commandline.co.uk/klocks/index.html), but perhaps you find it somewhere else. As an alternative commandline tool you could use the tool numlock.exe (http://www.rjlsoftware.com/software/utility/numlock/) but I am sure there exists other commandline tools like this. A third possibility may be to use a small VBS script to set the NUMLOCK state, but I have not tried it yet (see faq-o-matic.net):
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{NUMLOCK}"
Whichever script you choose, it shall be executed when you 'terminate' the RDP session. There are two possibilities to terminate a RDP session:
- disconnect from the remote user session by just closing the remote desktop window
- terminate the remote user session by logging off
For a simple 'disconnect from the remote user session' you should use the Windows task scheduler on the remote PC. Just define the trigger "disconnect from user session" and define as an action the 'NUMLOCK-on' script.
For 'logging off' from the remote user session, i. e. a real termination of the session, it's not easy to use the task scheduler because there exists no predefined trigger for 'logoff'. Instead you should use the local group policy editor to define a logoff script (in user configuration > Windows settings > Scripts > logoff).
BTW To be sure that NUMLOCK will always be activated on the remote computer when a remote user is logging on (i. e. not just entering an existing session) there are several possibilities:
- use the local group policy editor to define a logon script
- use the task scheduler to define a task with trigger 'logon'
- set the registry value InitialKeyboardIndicators to 2 (HKCU\Control Panel\Keyboard, see https://technet.microsoft.com/en-us/library/cc978657.aspx)
- use the different autorun possibilities in the registry