|
| 1 | +# PowerShell script used to patch termsrv.dll file and allow multiple RDP connections on Windows 10 (1809 and never) and Windows 11 |
| 2 | +# Details here http://woshub.com/how-to-allow-multiple-rdp-sessions-in-windows-10/ |
| 3 | + |
| 4 | + |
| 5 | +# Stop RDP service, make a backup of the termsrv.dllfile and change the permissions |
| 6 | +Stop-Service UmRdpService -Force |
| 7 | +Stop-Service TermService -Force |
| 8 | +$termsrv_dll_acl = Get-Acl c:\windows\system32\termsrv.dll |
| 9 | +Copy-Item c:\windows\system32\termsrv.dll c:\windows\system32\termsrv.dll.copy |
| 10 | +takeown /f c:\windows\system32\termsrv.dll |
| 11 | +$new_termsrv_dll_owner = (Get-Acl c:\windows\system32\termsrv.dll).owner |
| 12 | +cmd /c "icacls c:\windows\system32\termsrv.dll /Grant $($new_termsrv_dll_owner):F /C" |
| 13 | +# search for a pattern in termsrv.dll file |
| 14 | +$dll_as_bytes = Get-Content c:\windows\system32\termsrv.dll -Raw -Encoding byte |
| 15 | +$dll_as_text = $dll_as_bytes.forEach('ToString', 'X2') -join ' ' |
| 16 | +$patternregex = ([regex]'39 81 3C 06 00 00(\s\S\S){6}') |
| 17 | +$patch = 'B8 00 01 00 00 89 81 38 06 00 00 90' |
| 18 | +$checkPattern=Select-String -Pattern $patternregex -InputObject $dll_as_text |
| 19 | +If ($checkPattern -ne $null) { |
| 20 | + $dll_as_text_replaced = $dll_as_text -replace $patternregex, $patch |
| 21 | +} |
| 22 | +Elseif (Select-String -Pattern $patch -InputObject $dll_as_text) { |
| 23 | + Write-Output 'The termsrv.dll file is already patched, exiting' |
| 24 | + Exit |
| 25 | +} |
| 26 | +else { |
| 27 | + Write-Output "Pattern not found " |
| 28 | +} |
| 29 | +# patching termsrv.dll |
| 30 | +[byte[]] $dll_as_bytes_replaced = -split $dll_as_text_replaced -replace '^', '0x' |
| 31 | +Set-Content c:\windows\system32\termsrv.dll.patched -Encoding Byte -Value $dll_as_bytes_replaced |
| 32 | +# comparing two files |
| 33 | +fc.exe /b c:\windows\system32\termsrv.dll.patched c:\windows\system32\termsrv.dll |
| 34 | +# replacing the original termsrv.dll file |
| 35 | +Copy-Item c:\windows\system32\termsrv.dll.patched c:\windows\system32\termsrv.dll -Force |
| 36 | +Set-Acl c:\windows\system32\termsrv.dll $termsrv_dll_acl |
| 37 | +Start-Service UmRdpService |
| 38 | +Start-Service TermService |
| 39 | + |
0 commit comments