Last active
March 21, 2021 10:38
-
-
Save aachyee/69884b0902604f58febe9afbc7c4f579 to your computer and use it in GitHub Desktop.
VMWare Player Launcher Bat for Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| rem Usage: VMWarePlayerLauncher.bat [Path to .vmx files] | |
| setlocal enabledelayedexpansion | |
| set "errorlevel=" | |
| for %%a in (%*) do ( | |
| if "%%~xa"==".vmx" ( | |
| if exist "%%~a" ( | |
| set "result=" | |
| for /f "tokens=*" %%i in ('FINDSTR /C:"workingDir = " "%%~a"') do set "result=%%i" | |
| rem for /f "tokens=2 delims==" %%i in ("!result!") do set "result=%%i" | |
| set "workingDir=" | |
| if "!result!"=="" ( | |
| set "workingDir=%%~dpa" | |
| ) else ( | |
| set "result=!result:~13!" | |
| set "result=!result:~1,-1!" | |
| if exist "!result!" ( | |
| set "workingDir=!result!" | |
| ) else ( | |
| echo Error: WorkingDir not found.: "!result!" >&2 | |
| ) | |
| ) | |
| if not "!workingDir!"=="" ( | |
| cd "!workingDir!" | |
| ver > nul | |
| if exist "vmware.log" ( | |
| rem try "touch vmware.log" | |
| copy /b "vmware.log" +nul "vmware.log" >nul 2>&1 | |
| ) | |
| if not errorlevel 1 ( | |
| for /d %%d in (*.lck) do ( | |
| echo Removing "%%d" | |
| rmdir /S /Q "%%d" | |
| ) | |
| echo Starting "%%~na" | |
| start "C:\Program Files (x86)\VMware\VMware Player\vmplayer.exe" "%%~a" | |
| ) else ( | |
| echo Error: File has been locked.: "%%~a" >&2 | |
| ) | |
| ) | |
| ) else ( | |
| echo Error: File not found.: "%%~a" >&2 | |
| ) | |
| ) else if "%%~a"=="" ( | |
| rem skip | |
| rem title or break | |
| title>nul | |
| ) else ( | |
| echo Error: Not .vmx file.: "%%~a" >&2 | |
| ) | |
| ) | |
| rem exit /b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment