Skip to content

Instantly share code, notes, and snippets.

@ScottJWalter
Last active March 30, 2026 17:03
Show Gist options
  • Select an option

  • Save ScottJWalter/9db0b482360092bbe323693b624c232d to your computer and use it in GitHub Desktop.

Select an option

Save ScottJWalter/9db0b482360092bbe323693b624c232d to your computer and use it in GitHub Desktop.
Launches the most recent scrcpy-win64-vX.Y.Z build from the script's directory
@echo off
setlocal enabledelayedexpansion
set "SCRIPT_DIR=%~dp0"
set "BEST_MAJOR=-1"
set "BEST_MINOR=-1"
set "BEST_PATCH=-1"
set "BEST_NAME="
for /d %%D in ("%SCRIPT_DIR%scrcpy-win64-v*") do (
set "DNAME=%%~nxD"
set "VER=!DNAME:scrcpy-win64-v=!"
for /f "tokens=1,2,3 delims=." %%A in ("!VER!") do (
set "MAJ=%%A"
set "MIN=%%B"
set "PAT=%%C"
rem Validate all three tokens are purely numeric
set "VALID=1"
for /f "delims=0123456789" %%X in ("%%A%%B%%C") do set "VALID=0"
if "!VALID!"=="1" (
if !MAJ! gtr !BEST_MAJOR! (
set "BEST_MAJOR=!MAJ!" & set "BEST_MINOR=!MIN!" & set "BEST_PATCH=!PAT!" & set "BEST_NAME=!DNAME!"
) else if !MAJ! equ !BEST_MAJOR! (
if !MIN! gtr !BEST_MINOR! (
set "BEST_MAJOR=!MAJ!" & set "BEST_MINOR=!MIN!" & set "BEST_PATCH=!PAT!" & set "BEST_NAME=!DNAME!"
) else if !MIN! equ !BEST_MINOR! (
if !PAT! gtr !BEST_PATCH! (
set "BEST_MAJOR=!MAJ!" & set "BEST_MINOR=!MIN!" & set "BEST_PATCH=!PAT!" & set "BEST_NAME=!DNAME!"
)
)
)
)
)
)
if "!BEST_NAME!"=="" (
echo Error: No scrcpy-win64-vX.Y.Z directory found in %SCRIPT_DIR%
exit /b 1
)
cd /d "%SCRIPT_DIR%%BEST_NAME%"
scrcpy.exe %*
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$best = $null
Get-ChildItem -Path $scriptDir -Directory |
Where-Object { $_.Name -match '^scrcpy-win64-v(\d+)\.(\d+)\.(\d+)$' } |
ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Major = [int]$Matches[1]
Minor = [int]$Matches[2]
Patch = [int]$Matches[3]
}
} |
Sort-Object Major, Minor, Patch -Descending |
Select-Object -First 1 |
ForEach-Object { $best = $_ }
if (-not $best) {
Write-Error "No scrcpy-win64-vX.Y.Z directory found in $scriptDir"
exit 1
}
$scrcpyDir = Join-Path $scriptDir $best.Name
Push-Location $scrcpyDir
try {
& ".\scrcpy.exe" '--pause-on-exit=if-error' @args
} finally {
Pop-Location
}
' Get the directory where this script lives
strScriptDir = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\"))
' Find the most recent scrcpy-win64-vX.Y.Z subdirectory
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oRex = CreateObject("VBScript.RegExp")
oRex.Pattern = "^scrcpy-win64-v(\d+)\.(\d+)\.(\d+)$"
Dim bestMajor, bestMinor, bestPatch, bestName
bestMajor = -1 : bestMinor = -1 : bestPatch = -1 : bestName = ""
For Each oFolder In oFSO.GetFolder(strScriptDir).SubFolders
If oRex.Test(oFolder.Name) Then
Set oMatch = oRex.Execute(oFolder.Name)(0)
maj = CInt(oMatch.SubMatches(0))
min = CInt(oMatch.SubMatches(1))
pat = CInt(oMatch.SubMatches(2))
If maj > bestMajor Or _
(maj = bestMajor And min > bestMinor) Or _
(maj = bestMajor And min = bestMinor And pat > bestPatch) Then
bestMajor = maj : bestMinor = min : bestPatch = pat
bestName = oFolder.Name
End If
End If
Next
If bestName = "" Then
WScript.Echo "Error: No scrcpy-win64-vX.Y.Z directory found in " & strScriptDir
WScript.Quit 1
End If
strScrcpyDir = strScriptDir & bestName
strCommand = "cmd /c cd /d """ & strScrcpyDir & """ && scrcpy.exe"
For Each Arg In WScript.Arguments
strCommand = strCommand & " """ & Replace(Arg, """", """""""""") & """"
Next
CreateObject("Wscript.Shell").Run strCommand, 0, False
@ScottJWalter
Copy link
Copy Markdown
Author

  1. Place this version in the folder above the scrcpy.exe folder.
  2. Alter any shortcuts to run this version of the vbs file (from its directory)

More of a theory right now, but I'm tired of my shortcuts to my scrcpy windows breaking with every update because of the sub-directories. Since the .VBS file that ships with scrcpy is just a wrapper around 'scrcpy.exe', I just moved the wrapper and directory up to the directory that doesn't change with each update.

We'll see if this works after v3.3.4 ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment