SoFunction
Updated on 2025-03-09

Code to modify the 3389 port of remote desktop with VBS and add it to Windows Firewall

Save the following code as .vbs and double-click to run. Then restart the system and modify the default 3389 port of the system's remote desktop

'##################### 
'VBSModify the default port of remote desktop,and add toWindowsFirewall 
'author 
 '56868For the port to be set 
'##################### 

Set WshShell = ("") 
 "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber",56868,"REG_DWORD" 
 "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp\PortNumber",56868,"REG_DWORD" 


Function Addfirewall(name,port,state) 
 Set objFirewall = CreateObject("") 
 Set objPolicy =  
 
 Set objPort = CreateObject("") 
  = port 
  = name 
  = state 
 Set colPorts =  
 errReturn = (objPort) 
End Function 

call Addfirewall("Remote Desktop 56868",56868,1) 
set WshShell = nothing 

msgbox "Setting successful" 

Here are some additional additions to others

'**********************************************
'*BY r05e
'*Change the terminal service port number
 '**********************************************
Set WshShell=CreateObject("")
Function Imput()
imputport=InputBox("Please enter a port number. Note: This port number cannot be used by other programs at present, otherwise it will affect the terminal service.","Change terminal port number", "3389", 100, 100)
If imputport<>"" Then
If IsNumeric(imputport) Then

 "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp\PortNumber",imputport,"REG_DWORD"
 "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber",imputport,"REG_DWORD"
 "The operation is successful"
Else  "There is an error in input, please re-enter"
Imput()
End If
Else  "The operation has been cancelled"
End If
End Function
Imput()
set WshShell=nothing

This is the article about using VBS to modify the 3389 port of remote desktop and add the code to the Windows firewall. For more information about VBS to modify the default port of remote desktop, please search for my previous article or continue browsing the related articles below. I hope everyone will support me in the future!