A question on the terminal services newsgroup brought this topic to my attention: how can be determined programmatically if a Windows Server 2008 system is a terminal server and whether it runs in application server or remote administration mode? With Windows Server 2008 "terminal server" is a role that can be installed with the GUI tool Server Manager. If the role "terminal server" is installed then the system runs in application server mode. If not, it runs in remote administration mode. It is as simple as that. RDP connections can, however, be disallowed or limited to clients with Network Level Authentication (NLA). This is configured in the system's properties, accessible via:
SystemPropertiesAdvanced.exe -> Remote -> Remote Desktop
Now, how can these settings be queried programmatically?
Roles and features can be managed with the command line tool ServerManagerCmd.exe. Use the switch -query to get a listing of all roles and features and their current status (installed or not). Finding out how to query the Remote Desktop settings was a little harder. I used Process Monitor to spy on the registry activity ofSystemPropertiesAdvanced.exe when settings were applied and found the location where the relevant settings are stored. Here is a list of the three modes that can be set in the GUI and their corresponding registry values:
Don't allow connections to this computer
HKLM\System\CurrentControlSet\Control\Terminal Server\fDenyTSConnections = 1 HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\UserAuthentication = 0 HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\SecurityLayer = 1
Allow connections from computers running any version of Remote Desktop (less secure)
HKLM\System\CurrentControlSet\Control\Terminal Server\fDenyTSConnections = 0 HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\UserAuthentication = 0 HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\SecurityLayer = 1
Allow connections only from computers running Remote Desktop with Network Level Authentication (more secure)
HKLM\System\CurrentControlSet\Control\Terminal Server\fDenyTSConnections = 0 HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\UserAuthentication = 1 HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\SecurityLayer = 1
Wrapping it all up
I wrote a batch script that uses the techniques I described above and outputs the mode the terminal services on the local machine run in. The script was developed and tested on the June CTP release of Windows Server 2008. Feel free to use it in your own environment.