Showing posts with label windows firewall. Show all posts
Showing posts with label windows firewall. Show all posts

Enable remote desktop access, using command line

If you need to RDP into a windows box that you have commandline access to, this is for you.


  1. First, permit RDP through the firewall.

    netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
    
    
    
  2. Then, enable terminal services in the registry using the reg command:
    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
    
    
    
  3. Done!



To disable Remote Desktop access is just as easy:


  1. First, deny RDP through the firewall.

    netsh advfirewall firewall set rule group="remote desktop" new enable=No
    
    
    
  2. Then, disable terminal services in the registry using the reg command:
    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 1 /f
    
    
    
  3. Done!


Please note, you may need to reboot the windows machine for the changes to take effect (though problably not), and this doesn't work on "home" editions of Windows.

Disable Windows Firewall with VBS/Batch script

This is a simple VBS script to disable the specified computers' windows firewall using WMI, requires administrator access.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name = 'SharedAccess'")

For Each objService in colServiceList
    If objService.State = "Running" Then
        objService.StopService()
        Wscript.Sleep 5000
    End If
    errReturnCode = objService.ChangeStartMode("Disabled")   
Next

And if you can do it in VBS, you can do it in batch script!