Enable Remote Desktop using script

Enable the Remote Desktop feature on Windows computers using simple scripting or remote registry calls.

In order to enable Remote Desktop, what you need to do is change these registry keys either using Registry Editor (regedit.exe) or using Windows Scripting Host or other program that allows editing of the Windows Registry.  You can also enable Remote Desktop of a local computer by pressing Windows Key + Pause/Break, clicking Remote Settings, then choosing the “Allow Remote connections to this computer”, click OK to save.

The Registry Key

[HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\Terminal Server]
 "fDenyTSConnections"=dword:00000000
 "TSEnabled"=dword:00000001

As with all Windows Registry Editing – take care as you may end up breaking your computer.

User Permissions

In order to access a computer through Remote Desktop, your user account will need to be part of the “Remote Desktop Users” security group, by default the Administrator account is already part of the security group.   You can update the security group before or after enabling Remote Desktop by using the Computer Management Console, Batch scripting, or if you really like, Windows Scripting host.

This command will add a Domain user to the local security group.  Remember that you will need to be a local administrator of the machine so that you can add users to local groups.

net localgroup "Remote Desktop Users" %USERDOMAIN%\\administrator /add

It is easy to adapt this command so that local users can be used instead.  Just remove the %userdomain%\ bit from the command.

By Script

If you want to use Windows Scripting, then you can use the following file, just save the file with a .VBS or .WSH extention.  VBS can be ran as a computer startup script in Active Directory Group policy.

 \' This script adds users to the local Remote Desktop Users security group.
 \' Script is free for anyone to use.

\' Create a Network Object so that we can access local and network security info.
 Set oWshNet = CreateObject("WScript.Network")

\' Get the current Domain and Computer name that is calling the script.
 sNetBIOSDomain = oWshNet.UserDomain
 sComputer = oWshNet.ComputerName

\' Create an Object that will link to the Remote Desktop Users group
 Set oGroup = GetObject("WinNT://" & sComputer & "/Remote Desktop Users,group")

\' suppress errors in case the user is already a member
 On Error Resume Next

\' Create a Network User object for the Administrator.
 \' Note: replace Administrator with a username of your choice
 Set oUser = GetObject("WinNT://" & sNetBIOSDomain & "/" & "Administrator" & ",user")

\' Call the Group Object Add command to add our user to the group.
 oGroup.Add(oUser.ADsPath)

\' Create a Local User object for the Administrator.
 \' Note: replace Administrator with a username of your choice
 Set oUser = GetObject("WinNT://" & sComputer & "/" & "Administrator" & ",user")

\' Call the Group Object Add command to add our user to the group.
 oGroup.Add(oUser.ADsPath)

\' Error catchall
 On Error Goto 0

 

Use this information at your own risk.  For full details about using Scripting, visit http://www.microsoft.com/scripting

Similar Posts