Link to home
Start Free TrialLog in
Avatar of DjDezmond
DjDezmondFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VBScript - Enabling Remote Desktop

I have obtained a script to enable Remote Desktop:
---------------------------------------------------------------
cimv2_string = "WINMGMTS:" & "\\.\root\cimv2"
query = "select * from Win32_TerminalServiceSetting"
value_to_set = 1

set cimv2 = GetObject( cimv2_string )
set items = cimv2.ExecQuery( query )

for each item in items
      item.SetAllowTSConnections( value_to_set )
next
--------------------------------------------------------------
Once this script has executed, the tick box is ticked and everything seems to of worked OK. However, when I come to try and remote connect, it doesn't work (the connection just keeps trying until eventually timing-out).

If I unclick the tick box (the one that says "Allow users to connect remotely to this computer" in the system properties) and then re-click it again, the remote desktop connects with no problems. Its obvious that when you tick that box, a windows routine is executed that finalizes something. I need to know what this is so I can implement it into my script.

I have tried a few different scripts that do the same job, but with the same results...

Can anyone shine any light on why this is not working?

Thanks in advance...
Dez
Avatar of johnb6767
johnb6767
Flag of United States of America image

What about via a batch file?

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server]
"fAllowToGetHelp"=dword:00000000  <~~~Allows remote assistance
"fDenyTSConnections"=dword:00000000 <~~~Allows remote desktop, 1 turns it off...

Why are you using a script? Is there a reason you cannot use local policy or group policy?
Avatar of star_trek
star_trek

try changing this  cimv2_string = "WINMGMTS:" & "\\.\root\cimv2"
to cimv2_string = "winmgmts:" & "{impersonationLevel=impersonate}\\.\root\cimv2" and I tried and it works just fine



Avatar of DjDezmond

ASKER

I found the problem to be with Windows Firewall... when that checkbox is clicked, it adds that program to the firewall. When i execute the script, it doesn't. So now i just need to find out what port Remote Desktop runs on, and add that part to the script.

The script is bein written as part of a programme to automate windows builds for our clients. Once all the 'customization' scripts have been writted, images of the builds are automatically created and burned to DVD's. It make the whole process alot quicker.

Does anyone happen to know the executable and port that Remote Desktop uses? I would be able to find this myself normally, but my doc has just given me two weeks off work!

Cheers,
Dez
ASKER CERTIFIED SOLUTION
Avatar of johnb6767
johnb6767
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
just fyi...

http://www.microsoft.com/windowsxp/using/mobility/rdfaq.mspx

Excerpt from above link...

Q. What port does Remote Desktop use? Does everything go over port 3389?
A. Port 3389 is the only port you need to open. Windows will attempt to stream sound through User Datagram Protocol (UDP) first. If no port is available for UDP, sound will stream through a virtual channel in Remote Desktop Protocol, which uses port 3389.
 
Q. How do I connect Windows Desktop Client to a remote port other than 3389?
A. In the Computer field in the Remote Desktop Client connection dialog, specify the port in either of the following ways:

• Computer name, colon, port number

Example: TSComputer: 22229
 
• IP address, colon, port number

Example: 192.168.1.1: 22229