The state of remote desktop is stored in the DWORD value HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\fDenyTSConnections
- 1 = Disabled
- 0 = Enabled
Although you could connect to the remote registry and make the change a reboot will be required to enable it, a better alternative is to use WMI (Windows Management Instrumentation), Windows provides a handy WMI command line tool in the form of WMIC. To enable remote desktop to server MyServer:
-
wmic /node:”MyServer”RDToggle where servername=”MyServer”call SetAllowTSConnections 1
alternatively also specify a username and password for the remote system
-
wmic /node:”MyServer” /user:”username” /password:”password” RDToggle where servername=”MyServer” call SetAllowTSConnections 1
Note that an exception for Remote Desktop will also be added to the firewall exception list.
Have a few servers to enable? Try:
-
for %s in (MyServer1, MyServer2, MyServer3) do wmic /node:”%s” RDToggle where servername=”%s” call SetAllowTSConnections 1
Or a text file with a list of servers (file.txt), one per line? Try:
-
for /f %s in (file.txt) do wmic /node:”%s” RDToggle where servername=”%s” call SetAllowTSConnections 1