@echo off title Reset Scale Port (release stuck COM port) :: --- Self-elevate to Administrator (needed to reset the USB device) --- net session >nul 2>&1 if %errorLevel% neq 0 ( echo Requesting administrator rights... powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs" exit /b ) echo ============================================ echo Releasing / resetting the scale port echo ============================================ echo. echo This disables and re-enables the USB-serial echo scale adapter, which frees the COM port even echo if another app/tab is holding it. echo. powershell -NoProfile -ExecutionPolicy Bypass -Command ^ "$d = Get-PnpDevice -Class Ports -PresentOnly | Where-Object { $_.FriendlyName -match 'CH340|CH341|USB-SERIAL|USB Serial|CP210|FT232|FTDI|Prolific|PL2303|WCH' };" ^ "if (-not $d) { Write-Host 'No USB-serial scale adapter found. Make sure the scale is plugged in.'; }" ^ "foreach ($x in $d) {" ^ " Write-Host ('Resetting: ' + $x.FriendlyName + ' (' + $x.InstanceId + ')');" ^ " Disable-PnpDevice -InstanceId $x.InstanceId -Confirm:$false -ErrorAction SilentlyContinue;" ^ " Start-Sleep -Milliseconds 1000;" ^ " Enable-PnpDevice -InstanceId $x.InstanceId -Confirm:$false -ErrorAction SilentlyContinue;" ^ " Write-Host ' -> released and re-enabled.';" ^ "}" echo. echo Done. Wait ~3 seconds, then go back to the web app and click "Connect Scale". echo. pause