[Digress]
One day, I accidentally clicked the automatic repair of XX manager. Even though I canceled it in time, I also saw that the remote desktop service was successfully disabled, but I forgot it after I finished my work, you also forgot to enable the remote desktop service again before disconnecting it. That is why I thought that Azure had encountered a problem in the next few days, until I suddenly remembered that I forgot to re-open the Remote Desktop. Fortunately, XX manager didn't disable Powershell. We can use Powershell to enable remote desktop again.
[Article Index]
[1. essence of disabling remote desktop by XX Butler]
The Remote Desktop is disabled by using XX manager again, and the result is as follows:
If you enter the command directly, the following message is displayed:
| Out-string
If the remote desktop service is running, you can obtain the running status of the Remote Desktop service. For more information about the WMI class Win32_TerminalServiceSetting, see here, of course, if the operating system is 2K3 or below, the Namespace should be changed to ROOT \ CIMV2:
Get-WMIObject Win32_TerminalServiceSetting -Namespace ROOT\CIMV2\TerminalServices
For example, if the Remote Desktop is set to "do not allow connection to this computer", the following "AllowTSConnections" will be 0.
View Code
You can see that two parameters are acceptable: whether to enable Remote Desktop Connection and whether to modify the firewall exception settings. For example, you can use the following command to modify only Allow Remote Desktop Connection:
(Get-WMIObject Win32_TerminalServiceSetting -Namespace ROOT\CIMV2\TerminalServices).SetAllowTSConnections(1)
[4. Other problems that may cause remote desktop failure]
In addition to changing the remote desktop settings to "do not allow connection to this computer", Remote Desktop ports may not be enabled or disabled in firewall configuration.
If the remote desktop service is not enabled, we cannot set the Remote Desktop Through WMI in Powershell (obtaining and setting are not allowed, as the command is stuck and cannot continue ), therefore, we need to enable the remote desktop service:
If Remote Desktop Services is disabled, you can use the Set-Service command to first change it to manual startup (default ):
Set-Service -Name TermService -StartupType Manual
Then Start the Service using start-Service (of course, net Start is also supported ):
Start-Service -Name TermService
In addition to WMI, you can also use the netsh command to enable the Remote Desktop port in the firewall. We can use the following command to obtain the firewall rules. Of course, the Rule names are still different in different operating systems, here is the rule name for the Chinese version of Windows Server 2008 R2:
netsh advfirewall firewall show rule name=
You can also use the following command to enable these rules. The operating system here is the same as above. If it is an English operating system, replace it with "remote desktop ":
netsh advfirewall firewall set rule group= new enable=Yes
However, this method is much more complex than WMI.
[Related link]