Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบ >> Windows 11

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

Remote Users เชื่อมต่อ Windows 10/11 ผ่าน Remote Desktop Services (RDP) เพียงเปิด RDP ใน Settings แล้วเชื่อมต่อด้วย Remote Desktop Client แต่มีข้อจำกัด: มีเพียง 1 Remote User พร้อมกันเท่านั้น หากพยายามเปิด Session ที่ 2 จะมี Warning ขอ Disconnect User คนแรก

Another user is signed in. If you continue, they’ll be disconnected. Do you want to sign in anyway?

Desktop Windows Versions (รวม Win 10/11) มีข้อจำกัด RDP:

  1. เชื่อมต่อ RDP เข้าได้เฉพาะ Edition สูง (Pro/Enterprise) Home/Single Language ห้าม Incoming RDP;
  2. รองรับ Simultaneous RDP Connection เพียง 1 Session พยายาม Session ที่ 2 จะถูกขอปิด Session เดิม;
  3. หากมี User ทำงานบน Console (Local) แล้ว พยายามสร้าง RDP Session ใหม่ Console Session จะถูก Disconnect และในทางกลับกัน หาก User Local Login ระหว่าง RDP Session ระยะไกล จะถูก Disconnect ทันที

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

จริงๆ จำนวน Simultaneous RDP Connections ถูกจำกัดโดย License ไม่ใช่ Technical Limitation จึงไม่สามารถสร้าง Terminal RDP Server จาก Workstation ได้ Microsoft ต้องการให้ซื้อ Windows Server License, RDS CALs, ติดตั้ง Role RDSH

Technically Windows Version ใดก็ตามที่มี RAM พอ สามารถรองรับ Remote Users หลายสิบคนได้ (เฉลี่ย 150-200 MB RAM ต่อ Session ไม่นับ Apps) จำนวน Session สูงสุดขึ้นกับ Resources ของเครื่อง

บทความนี้เสนอ 2 วิธีอนุญาต Simultaneous RDP Connections บน Windows 10/11: ใช้ RDP Wrapper หรือ Patch termsrv.dll

Note การแก้ไข System ตามบทความถือว่าละเมิด Microsoft License Agreement ใช้ด้วยความเสี่ยงของตัวเอง

RDP Wrapper: เปิดใช้งาน Multiple RDP Sessions บน Windows

RDP Wrapper Library OpenSource Project อนุญาต Multiple RDP Sessions บน Windows 10 โดยไม่แทนที่ termsrv.dll Tool นี้ทำงานเป็น Layer ระหว่าง SCM (Service Control Manager) และ Remote Desktop Services RDPWrap เปิดใช้งาน Multiple Simultaneous RDP Connections และสร้าง RDP Server บน Windows Home Editions ได้ RDP Wrapper ไม่แก้ไข termsrv.dll แค่ Load Library ด้วย Parameters ที่เปลี่ยนแล้ว

ดังนั้น RDPWrap ทำงานได้แม้ termsrv.dll ถูก Update ผ่าน Windows Updates

Important ก่อนติดตั้ง RDP Wrapper ต้องแน่ใจว่าใช้ termsrv.dll ต้นฉบับ (Unpatched) มิฉะนั้น RDP Wrapper อาจ Unstable หรือเริ่มไม่ได้

ดาวน์โหลด RDP Wrapper จาก GitHub: https://github.com/binarymaster/rdpwrap/releases (Latest v1.6.2) Project ไม่ได้ Update ตั้งแต่ 2017 แต่ใช้ได้กับ Build ใหม่ของ Windows 10 และ Windows 11

RDPWrap-v1.6.2.zip มีไฟล์:

  • RDPWinst.exe — Install/Uninstall Program;
  • RDPConf.exe — Configuration Tool;
  • RDPCheck.exe — Local RDP Checker;
  • install.bat, uninstall.bat, update.bat — Batch Files สำหรับ Install, Uninstall, Update

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

ติดตั้ง: รัน install.bat as Admin ติดตั้งที่ C:\Program Files\RDP Wrapper

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

หลังติดตั้ง รัน RDPConfig.exe อาจแสดง RDP Wrapper Running (Installed, Running, Listening) แต่ Not Working มี Warning แดง [not supported] รายงานว่า Windows 10 Build นี้ (ver. 10.0.19041.1320) ไม่ได้รับ Support จาก RDPWrapper

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

เหตุผล: แต่ละ Windows 10 Build ต้องมี Description ใน rdpwrap.ini Config File Config ของคุณไม่มี Settings สำหรับ Build นี้

rdpwrap.ini เวอร์ชันปัจจุบัน ดาวน์โหลดได้ที่: https://raw.githubusercontent.com/sebaxakerhtc/rdpwrap.ini/master/rdpwrap.ini

คัดลอกเนื้อหาไปไฟล์ “C:\Program Files\RDP Wrapper\rdpwrap.ini” หรือดาวน์โหลดด้วย PowerShell (หยุด Remote Desktop Service ก่อน):

Stop-Service termservice -Force
Invoke-WebRequest https://raw.githubusercontent.com/sebaxakerhtc/rdpwrap.ini/master/rdpwrap.ini -outfile "C:\Program Files\RDP Wrapper\rdpwrap.ini"

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

Restart เครื่อง รัน RDPConfig.exe ตรวจสอบ Diagnostics ทั้งหมดเป็นสีเขียว และ Caption [Fully supported] โชว์ว่า RDP Wrapper กับ Config ใหม่ ทำงานได้บน Windows 11 ด้วย

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

ลองสร้างหลาย RDP Sessions (ใช้ Client ใดก็ได้: mstsc.exe, rdcman) ทำงานได้ดี (ยังใช้ Saved Credentials ได้) ตอนนี้ Windows 10 อนุญาต 2 (หรือมากกว่า) Remote Users ใช้ RDP Sessions พร้อมกัน

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

RDPWrap รองรับทุก Edition สร้าง Terminal (RDS) Server บน Windows Device ใดก็ได้

RDP Wrapper ยังทำได้:

  • Enable Remote Desktop;
  • Option Hide users on logon screen ซ่อน User List บน Logon Screen;
  • Disable Single session per user อนุญาต Multiple Simultaneous RDP Sessions ภายใต้ User Account เดียวกัน (Registry fSingleSessionPerUser = 0 ที่ HKLM\SYSTEM\ CurrentControlSet\Control\Terminal Server\fSingleSessionPerUser);
  • RDP Port เปลี่ยน Port 3389 เป็น Port อื่น;
  • Session Shadowing Mode ตั้งค่า Remote Control (Shadow) Mode

ตั้งค่าขีดจำกัดระยะเวลา RDP Sessions ได้ด้วย GPO

RDP Wrapper Not Working บน Windows 10

บางกรณี RDP Wrapper ไม่ทำงาน ไม่สามารถ Multiple RDP Sessions ได้

หาก Utility แสดง [not supported] ใน Section Status แปลว่า rdpwrap.ini ไม่มี Config สำหรับ Build นี้ ให้ Update rdpwrap.ini ตามข้างต้น

หากยังไม่ทำงานหลัง Update ให้เปิด rdpwrap.ini หา Section สำหรับ Windows Version ของคุณ วิธีรู้ว่า Config รองรับ Build นี้หรือไม่?

ภาพด้านล่างแสดงว่า Windows 10 Version 10.0.19041.1320 มี 2 Description Sections:

[10.0.19041.1320] ….. [10.0.19041.1320-SLInit] …..

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

หากไม่มี Section สำหรับ Build ของคุณ ลอง Google คำว่า rdpwrap.ini strings สำหรับ Build นั้น เพิ่มบรรทัดที่หาได้ลงท้ายไฟล์

หากมีปัญหากับ RDPWrapper สร้าง Issue ที่ https://github.com/stascorp/rdpwrap/issues ที่นี่ก็หา rdpwrap.ini ล่าสุดได้

หากหลังติดตั้ง Security Updates หรือ Upgrade Windows 10 Build RDP Wrapper ไม่ทำงาน ตรวจสอบว่า Diagnostics แสดง “Listener state: Not listening”

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

ลอง Update rdpwrap.ini แล้ว Reinstall Service:

rdpwinst.exe -u
rdpwinst.exe -i

บางครั้งพยายาม Session ที่ 2 ภายใต้ User Account อื่น ได้ Warning:

The number of connections to this computer is limited and all connections are in use right now. Try connecting later or contact your system administrator.

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

แก้ด้วย Local Group Policy Editor (gpedit.msc) Enable Policy “Limit number of connections” ที่ Computer Configuration -> Administrative Templates -> Windows Components -> Remote Desktop Services -> Remote Desktop Session Host -> Connections ตั้งค่าเป็น 999999

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

Restart เพื่อ Update GPO และ Apply Settings

แก้ไข Termsrv.dll เพื่อเปิด Multiple RDP Sessions

วิธีลบข้อจำกัด Simultaneous RDP Connections โดยไม่ใช้ RDPWrapper คือ แทนที่ ไฟล์ termsrv.dll ต้นฉบับ ไฟล์ Library หลักของ Remote Desktop Service อยู่ที่ C:\Windows\System32

ก่อนแก้/แทนที่ termsrv.dll ควร Backup ไฟล์ต้นฉบับ เปิด CMD as Admin รัน:

copy c:\Windows\System32\termsrv.dll termsrv.dll_backup

Take Ownership ของไฟล์ จาก TrustedInstaller เป็น Local Administrators Group:

takeown /F c:\Windows\System32\termsrv.dll /A

SUCCESS: The file (or folder): c:\Windows\System32\termsrv.dll now owned by the administrators group

Grant Full Control ให้ Administrators Group:

icacls c:\Windows\System32\termsrv.dll /grant Administrators:F

processed file: c:\Windows\System32\termsrv.dll Successfully processed 1 files; Failed processing 0 files.

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

หยุด Remote Desktop Service (TermService) ผ่าน services.msc หรือ CMD:

Net stop TermService

Remote Desktop Services UserMode Port Redirector Service ก็จะหยุดตามไปด้วย

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

หา Windows 10 Build Number: PowerShell รัน Get-ComputerInfo | select WindowsProductName, WindowsVersion ในตัวอย่างเป็น Build 21H1

เปิด termsrv.dll ด้วย HEX Editor (เช่น Tiny Hexer) ขึ้นกับ Build ต้อง Find และ Replace String ตามตาราง:

Windows Build Find String Replace With
Windows 11 RTM (21H2 – 22000.258) 39 81 3C 06 00 00 0F 84 4F 68 01 00 B8 00 01 00 00 89 81 38 06 00 00 90
Windows 10 x64 21H2 39 81 3C 06 00 00 0F 84 DB 61 01 00
Windows 10 x64 21H1 39 81 3C 06 00 00 0F 84 2B 5F 01 00
Windows 10 x64 20H2 39 81 3C 06 00 00 0F 84 21 68 01 00
Windows 10 x64 2004 39 81 3C 06 00 00 0F 84 D9 51 01 00
Windows 10 x64 1909 39 81 3C 06 00 00 0F 84 5D 61 01 00
Windows 10 x64 1903 39 81 3C 06 00 00 0F 84 5D 61 01 00
Windows 10 x64 1809 39 81 3C 06 00 00 0F 84 3B 2B 01 00
Windows 10 x64 1803 8B 99 3C 06 00 00 8B B9 38 06 00 00
Windows 10 x64 1709 39 81 3C 06 00 00 0F 84 B1 7D 02 00

Tiny Hexer ไม่สามารถ Edit termsrv.dll ใน System32 โดยตรง Copy ไป Desktop แก้ไข แล้ว Copy กลับแทนที่

ตัวอย่าง Build 21H1 (19043.1320) termsrv.dll version 10.0.19041.1320 เปิดใน Tiny Hexer Find:

39 81 3C 06 00 00 0F 84 2B 5F 01 00

Replace ด้วย:

B8 00 01 00 00 89 81 38 06 00 00 90

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

Save File และ Start TermService

หากมีปัญหา หยุด Service แทนที่ termsrv.dll ด้วย Backup:

copy termsrv.dll_backup c:\Windows\System32\termsrv.dll

Patch Termsrv.dll บน Windows ด้วย PowerShell

แทนที่จะแก้ Manual ด้วย HEX Editor ใช้ PowerShell Script Patch อัตโนมัติ Script นี้ใช้ Windows PowerShell (ไม่ใช่ PowerShell Core) Universal สำหรับ Windows 10 (1809+) และ Windows 11 ทุก Edition

# Stop RDP service, make a backup of the termsrv.dllfile and change the permissions
Stop-Service UmRdpService -Force
Stop-Service TermService -Force
$termsrv_dll_acl = Get-Acl c:\windows\system32\termsrv.dll
Copy-Item c:\windows\system32\termsrv.dll c:\windows\system32\termsrv.dll.copy
takeown /f c:\windows\system32\termsrv.dll
$new_termsrv_dll_owner = (Get-Acl c:\windows\system32\termsrv.dll).owner
cmd /c "icacls c:\windows\system32\termsrv.dll /Grant $($new_termsrv_dll_owner):F /C"
# search for a pattern in termsrv.dll file
$dll_as_bytes = Get-Content c:\windows\system32\termsrv.dll -Raw -Encoding byte
$dll_as_text = $dll_as_bytes.forEach('ToString', 'X2') -join ' '
$patternregex = ([regex]'39 81 3C 06 00 00(\s\S\S){6}')
$patch = 'B8 00 01 00 00 89 81 38 06 00 00 90'
$checkPattern=Select-String -Pattern $patternregex -InputObject $dll_as_text
If ($checkPattern -ne $null) {
$dll_as_text_replaced = $dll_as_text -replace $patternregex, $patch
}
Elseif (Select-String -Pattern $patch -InputObject $dll_as_text) {
Write-Output 'The termsrv.dll file is already patch, exitting'
Exit
}
else {
Write-Output "Pattern not found "
}
# patching termsrv.dll
[byte[]] $dll_as_bytes_replaced = -split $dll_as_text_replaced -replace '^', '0x'
Set-Content c:\windows\system32\termsrv.dll.patched -Encoding Byte -Value $dll_as_bytes_replaced
# comparing two files
fc.exe /b c:\windows\system32\termsrv.dll.patched c:\windows\system32\termsrv.dll
# replacing the original termsrv.dll file
Copy-Item c:\windows\system32\termsrv.dll.patched c:\windows\system32\termsrv.dll -Force
Set-Acl c:\windows\system32\termsrv.dll $termsrv_dll_acl
Start-Service UmRdpService
Start-Service TermService

Full Script: https://github.com/maxbakhub/winposh/blob/main/termsrv_rdp_patch.ps1

รัน Script: ดาวน์โหลดมา เปลี่ยน Execution Policy: Set-ExecutionPolicy Bypass -Scope Process -Force รัน: C:\users\root\desktop\termsrv_rdp_patch.ps1

วิธีอนุญาต Multiple RDP Sessions ใน Windows 10 และ 11

Script นี้รันได้หลังติดตั้ง Windows Updates เพื่อ Patch termsrv.dll ทันที (ไม่ต้องแก้ HEX Editor ทุกครั้ง)

ข้อดีของการ Patch termsrv.dll: Antivirus ไม่ Detect (ไม่เหมือน RDPWrap ที่ถูก Detect เป็น Malware/HackTool/Trojan)

ข้อเสีย: ต้อง Patch termsrv.dll ใหม่ทุกครั้งที่ Upgrade Windows 10 Build (หรือ Update termsrv.dll ผ่าน Cumulative Updates) หากใช้ RDPWrapper ก็ต้อง Update rdpwrap.ini หลัง Windows Updates เช่นกัน

บทความนี้สรุปวิธีลบข้อจำกัด Simultaneous RDP User Connections และรัน Terminal Server ฟรีบน Desktop Windows