- Enable remote desktop from command line (CMD)
- Enable remote desktop from CMD
- Enable Remote assistance:
- Run command for remote desktop (RDP client)
- Mstsc command
- Run command for opening remote desktop session in full screen mode
- Run command for specifying the remote computer name from the command itself
- Run command to specify remote desktop connection settings using a rdp file
- Run command for Remote desktop manager
- Relevant Posts:
- Windows commands
- Prerequisites
- Command shell overview
- Command-line reference A-Z
- Running Remote Commands
- Windows PowerShell Remoting Without Configuration
- Windows PowerShell Remoting
- Start an Interactive Session
- Run a Remote Command
- Run a Script
- Establish a Persistent Connection
- Advanced Remoting
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
- Change the data of the value fDenyTSConnections to 0.
We can enable remote desktop from windows command line by running the following command.
To disable remote desktop we need to run the below command.
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:
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.
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.
Thanks Jo for pointing that out. Now I have placed the commands in a code block ; copy & paste would work fine.
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.
Option 1:
You can run the below command for each user you want to allow to connect remotely.
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.
Thanx for this cool tip it helped me in creating my batch file which maybe dangerous for my target friends… 🙂
I want to create something like this as well but there’s a few problems
great job. thank u
So, i take the given command line to enable or disable the remote access, but it tells me Error: Access denied
I guess you are not running it from elevated command prompt.
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.
Where /f = full screen
/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
Thank you for your information..
Awesome…
Thanks man…
How can i add specific IPs to allow remote session?
Regards,
[email protected]
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…
Thank! good shared
Thank you for suggestion.
Please send me your email id. i can learn many more.
Thanks, This post help me lot.
hi danish,
this batch file will act on every Windows edition
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?
You could use PsExec to open an remote command prompt. Thus you need to download PsTools Suite from Microsoft Tech-Net.
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?
Yeah, this doesn’t work. You’re missing one critical step – opening the firewall
netsh firewall set service remotedesktop enable
mstsc /v:SERVER /admin
lol lol lol thank you Matthew Bradley, I couldn’t find this vital piece of information for like 20 minutes on google.
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))
Why to enable RDP from command line? Simple use remote access tools.
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!
Run command for remote desktop (RDP client)
The Run command for Windows Remote desktop application is Mstsc
Just open Run from start menu and type mstsc in the text box next to open and press enter.
This command mstsc can be used from command line too.
A system running Windows 7/Windows 10 allows only one remote desktop connection at a time, means only one remote user can work on it any time. A computer running Windows server edition can support remote sessions for multiple users at the same time.
Mstsc command
Every time we connect to the server it opens a new user session. To avoid this we can open a connection to the console. This allows us to login back to the same user session if we already have one. To do this we need to add /console switch to the mstsc command.
This command can be run from command prompt or from Run window.
Run command for opening remote desktop session in full screen mode
Add /f switch to the command.
Run command for specifying the remote computer name from the command itself
Use /v switch in this case.
Run command to specify remote desktop connection settings using a rdp file
A RDP file can be created using the ‘Save As‘ button in the General tab in mstsc(Remote desktop connection client) window.
These commands work on XP, Vista, Windows 7 and Server 2003/2008 operating systems.
Run command for Remote desktop manager
There is no Run command for opening remote desktop connection manager directly. It is usually installed in the path C:\Program Files\Remote Desktop Connection Manager\RDCman.exe . By specifying this complete path we can launch connection manager.
Relevant Posts:
Good information on the command line switches available with the mstsc command. thank you.
i would like to write command script to check whether the servers could RDP or not.
we have around 30 servers hence cant run mstsc /v:servername for each. Hence just would like to write cmd script to check all the servers. Could you please help me ?
can you please assist me with the system to enable remote access desktop/working into the network user without being there physically,i have i.p address and computer name of the workstation and we are all in one network.
Possibly you only have Windows Home Edition, which doesn’t support Remote Connections.
Remote Desktop Assistance is a feature of Windows Pro Editions.
can user able to see the desktop in mstsc command
It is not mstsc/console anymore. Now it is mstsc/admin. You can also add it to a desktop shortcut by changing the Target to %windir%\system32\mstsc.exe -admin
“admin” is different than “console” actually. Admin allows you to boot another user. My bad.
Hello..is there any option to trigger MSTC on windows boot up, preferably with pre-specified destination server and credentials?
Also, if the user logs out of the terminal server, he should get logged out of the local desktop as well.
I don’t want to give the user the option of a local desktop.
Windows commands
All supported versions of Windows (server and client) have a set of Win32 console commands built in.
This set of documentation describes the Windows Commands you can use to automate tasks by using scripts or scripting tools.
Prerequisites
The information that is contained in this topic applies to:
- Windows Server 2019
- Windows Server (Semi-Annual Channel)
- Windows Server 2016
- Windows Server 2012 R2
- Windows Server 2012
- Windows Server 2008 R2
- Windows Server 2008
- Windows 10
- Windows 8.1
Command shell overview
The Command shell was the first shell built into Windows to automate routine tasks, like user account management or nightly backups, with batch (.bat) files. With Windows Script Host you could run more sophisticated scripts in the Command shell. For more information, see cscript or wscript. You can perform operations more efficiently by using scripts than you can by using the user interface. Scripts accept all Commands that are available at the command line.
Windows has two command shells: The Command shell and PowerShell. Each shell is a software program that provides direct communication between you and the operating system or application, providing an environment to automate IT operations.
PowerShell was designed to extend the capabilities of the Command shell to run PowerShell commands called cmdlets. Cmdlets are similar to Windows Commands but provide a more extensible scripting language. You can run Windows Commands and PowerShell cmdlets in Powershell, but the Command shell can only run Windows Commands and not PowerShell cmdlets.
For the most robust, up-to-date Windows automation, we recommend using PowerShell instead of Windows Commands or Windows Script Host for Windows automation.
You can also download and install PowerShell Core, the open source version of PowerShell.
Incorrectly editing the registry may severely damage your system. Before making the following changes to the registry, you should back up any valued data on the computer.
To enable or disable file and directory name completion in the Command shell on a computer or user logon session, run regedit.exe and set the following reg_DWOrd value:
To set the reg_DWOrd value, use the hexadecimal value of a control character for a particular function (for example, 0 9 is Tab and 0 08 is Backspace). User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings.
Command-line reference A-Z
To find information about a specific command, in the following A-Z menu, click the letter that the command starts with, and then click the command name.
Running Remote Commands
You can run commands on one or hundreds of computers with a single PowerShell command. Windows PowerShell supports remote computing by using various technologies, including WMI, RPC, and WS-Management.
PowerShell Core supports WMI, WS-Management, and SSH remoting. In PowerShell 6, RPC is no longer supported. In PowerShell 7 and above, RPC is supported only in Windows.
For more information about remoting in PowerShell Core, see the following articles:
Windows PowerShell Remoting Without Configuration
Many Windows PowerShell cmdlets have the ComputerName parameter that enables you to collect data and change settings on one or more remote computers. These cmdlets use varying communication protocols and work on all Windows operating systems without any special configuration.
These cmdlets include:
Typically, cmdlets that support remoting without special configuration have the ComputerName parameter and don’t have the Session parameter. To find these cmdlets in your session, type:
Windows PowerShell Remoting
Using the WS-Management protocol, Windows PowerShell remoting lets you run any Windows PowerShell command on one or more remote computers. You can establish persistent connections, start interactive sessions, and run scripts on remote computers.
To use Windows PowerShell remoting, the remote computer must be configured for remote management. For more information, including instructions, see About Remote Requirements.
Once you have configured Windows PowerShell remoting, many remoting strategies are available to you. This article lists just a few of them. For more information, see About Remote.
Start an Interactive Session
To start an interactive session with a single remote computer, use the Enter-PSSession cmdlet. For example, to start an interactive session with the Server01 remote computer, type:
The command prompt changes to display the name of the remote computer. Any commands that you type at the prompt run on the remote computer and the results are displayed on the local computer.
To end the interactive session, type:
For more information about the Enter-PSSession and Exit-PSSession cmdlets, see:
Run a Remote Command
To run a command on one or more computers, use the Invoke-Command cmdlet. For example, to run a Get-UICulture command on the Server01 and Server02 remote computers, type:
The output is returned to your computer.
Run a Script
To run a script on one or many remote computers, use the FilePath parameter of the Invoke-Command cmdlet. The script must be on or accessible to your local computer. The results are returned to your local computer.
For example, the following command runs the DiskCollect.ps1 script on the remote computers, Server01 and Server02.
Establish a Persistent Connection
Use the New-PSSession cmdlet to create a persistent session on a remote computer. The following example creates remote sessions on Server01 and Server02. The session objects are stored in the $s variable.
Now that the sessions are established, you can run any command in them. And because the sessions are persistent, you can collect data from one command and use it in another command.
For example, the following command runs a Get-HotFix command in the sessions in the $s variable and it saves the results in the $h variable. The $h variable is created in each of the sessions in $s, but it doesn’t exist in the local session.
Now you can use the data in the $h variable with other commands in the same session. The results are displayed on the local computer. For example:
Advanced Remoting
Windows PowerShell remote management just begins here. By using the cmdlets installed with Windows PowerShell, you can establish and configure remote sessions both from the local and remote ends, create customized and restricted sessions, allow users to import commands from a remote session that actually run implicitly on the remote session, configure the security of a remote session, and much more.
Windows PowerShell includes a WSMan provider. The provider creates a WSMAN: drive that lets you navigate through a hierarchy of configuration settings on the local computer and remote computers.
For more information about the WSMan provider, see WSMan Provider and About WS-Management Cmdlets, or in the Windows PowerShell console, type Get-Help wsman .
For more information, see:
For help with remoting errors, see about_Remote_Troubleshooting.