Submitted By: carlos E. dos Santos

Changes the listening port for Remote Desktop (RDP).

Visual Basic
Edit|Remove
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &  _
    strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp"
strValueName = "PortNumber"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

Titulo     = "Microsoft TechNet"
Message    = "Porta RDP atual: " & dwValue & ", confirma alteração?"
Fim        = "Alteração efetuada com sucesso!"
Erro	   = "Valor informado incorreto!"
IntDoIt    = MsgBox(Message,vbyesno + vbInformation,Titulo )
If intDoIt = vbno Then WScript.Quit

porta=Inputbox("Digite a nova porta RDP desejada", "Unique Solution")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If porta = "" Then WScript.Quit

On Error Resume Next
if porta < 0 Then
	IntDoIt =  MsgBox(Erro, vbInformation,Titulo)
	WScript.Quit
Else
	strKeyPath = "SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp"
	strValueName = "PortNumber"
	dwValue = porta
	oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
End If

IntDoIt =  MsgBox(Fim, vbInformation,Titulo)