When it comes to remote access on our Windows devices, having the freedom to use Remote Desktop Protocol (RDP) sessions can greatly enhance our productivity. However, some Windows editions impose restrictions on Terminal Services, leaving us puzzled and searching for solutions. That’s where RDPWrap comes to the rescue, providing a magical workaround that enables RDP sessions even on those restricted devices. Yet, there’s a small catch: RDPWrap tends to stop working after Windows updates, which can be frustrating. To alleviate this inconvenience, I’ve made a straightforward PowerShell script that I’m sharing with you today. It effortlessly retrieves an updated version of the .ini file from GitHub and updates your local configuration. Bid farewell to the wretched connection failure dialog from RDP after updates and struggling with manual adjustments to the .ini.
The Code
The PowerShell script is rather simple. All it does is go out to a GitHub repository and grab the latest .ini file. From there, it compares the updated dates between the two files and overwrites the local file if the remote file is newer.
# # Configurables $remoteIniUri = "https://raw.githubusercontent.com/sebaxakerhtc/rdpwrap.ini/master/rdpwrap.ini" $localIniPath = "C:\Program Files\RDP Wrapper\rdpwrap.ini" # # Functions function Get-IniContent($file) { $ini = @{} switch -Regex -File $file { “^\[(.+)\]” # Section { $section = $matches[1] $ini[$section] = @{} $CommentCount = 0 } “(.+?)\s*=(.*)” # Key { $name,$value = $matches[1..2] $ini[$section][$name] = $value } } return $ini } # # Get the ini and write to temporary file $tempIniPath = [System.IO.Path]::GetTempFileName(); try { $webResponse = Invoke-WebRequest -Uri $remoteIniUri -Method Get [System.IO.File]::WriteAllText($tempIniPath, $webResponse.Content) # # Load the content of the remote and local ini $remoteIni = Get-IniContent $tempIniPath $localIni = Get-IniContent $localIniPath # Is the remote one newer? if ($remoteIni["Main"] -ne $null -and $remoteIni["Main"]["Updated"] -ne $null) { if ($localIni["Main"] -ne $null -and $localIni["Main"]["Updated"] -ne $null) { $remoteUpdatedDate = [DateTime]::Parse($remoteIni["Main"]["Updated"]) $localUpdatedDate = [DateTime]::Parse($localIni["Main"]["Updated"]) if ($remoteUpdatedDate -gt $localUpdatedDate) { Write-Host "Remote ini ($($remoteUpdatedDate)) is newer than the local ini ($($localUpdatedDate))" # Stop terminal services Write-Host "Stopping terminal services..." Stop-Service -Name TermService -Force Write-Host "Terminal services stopped." # Overwrite the local ini with the remote ini content Write-Host "Updating local ini..." [System.IO.File]::WriteAllText($localIniPath, $webResponse.Content) Write-Host "Local ini updated." # Start terminal services Write-Host "Starting terminal services..." Start-Service -Name TermService Write-Host "Terminal services started." } else { Write-Host "Local ini ($($localUpdatedDate)) is up to date." } } else { Write-Error "Local ini is missing required section data Main->Updated"; } } else { Write-Error "Remote ini is missing required section data Main->Updated"; } } catch { Write-Error "Unexpected error ocurred:" Write-Error $_ }
To automate the process, I use the Windows Task Scheduler and set up a simple task that runs on Startup (seeing Window’s update is really the thing that causes RDPWrap to break for us) that executes powershell.exe -File "<PathToScript>.ps1" -ExecutionPolicy Bypass
. This way, every time your computer starts up, you’ll have the latest version of the RDPWrap .ini ready to go!
Special Thanks
Special thanks to Stascorp for the excellent RDPWrap library and to Sebaxakerhtc for providing regularly updated .ini files for RDPWrap. Without either, remote sessions to my home computer would be significantly more annoying.