Reklam
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
:: ===== Start + Show Consoles + Safe-Resume Fix (WS 15.5.7) =====
:: - Deletes stale suspend/lock files (*.vmss, *.lck) to avoid "Resuming..." state after power loss
:: - Starts VMs and opens their GUI windows
:: - Adds 15s delay between VMs
set "ROOT=E:\AUTO"
set "DELAY=5"
set "LOG=%TEMP%\vm_boot_show_gui_RESUME_FIX.log"
set "VMRUN32=C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe"
set "VMRUN64=C:\Program Files\VMware\VMware Workstation\vmrun.exe"
set "VMWARE32=C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe"
set "VMWARE64=C:\Program Files\VMware\VMware Workstation\vmware.exe"
set "VMPLAYER32=C:\Program Files (x86)\VMware\VMware Workstation\vmplayer.exe"
set "VMPLAYER64=C:\Program Files\VMware\VMware Workstation\vmplayer.exe"
set "VMRUN="
if exist "%VMRUN64%" set "VMRUN=%VMRUN64%"
if exist "%VMRUN32%" set "VMRUN=%VMRUN32%"
set "VMGUI="
if exist "%VMWARE64%" set "VMGUI=%VMWARE64%"
if exist "%VMWARE32%" set "VMGUI=%VMWARE32%"
if "%VMGUI%"=="" (
if exist "%VMPLAYER64%" set "VMGUI=%VMPLAYER64%"
if exist "%VMPLAYER32%" set "VMGUI=%VMPLAYER32%"
)
echo ==== %DATE% %TIME% : start_and_show_vms_RESUME_FIX ==== > "%LOG%"
echo ROOT=%ROOT% >> "%LOG%"
echo DELAY=%DELAY% >> "%LOG%"
echo VMRUN="%VMRUN%" >> "%LOG%"
echo VMGUI="%VMGUI%" >> "%LOG%"
if "%VMRUN%"=="" (
echo [ERROR] vmrun.exe not found. See log: "%LOG%"
>> "%LOG%" echo [ERROR] vmrun.exe not found.
type "%LOG%"
exit /b 1
)
if "%VMGUI%"=="" (
echo [ERROR] vmware.exe/vmplayer.exe not found. See log: "%LOG%"
>> "%LOG%" echo [ERROR] No GUI binary found.
type "%LOG%"
exit /b 1
)
if not exist "%ROOT%" (
echo [ERROR] ROOT not found: "%ROOT%"
>> "%LOG%" echo [ERROR] ROOT not found.
type "%LOG%"
exit /b 2
)
:: Ensure Authorization Service is running (required by Workstation on Windows)
set "AUTH_SERVICE=VMware Authorization Service"
sc query "%AUTH_SERVICE%" | find /I "RUNNING" >nul
if errorlevel 1 (
echo [INFO] Starting "%AUTH_SERVICE%" ...
>> "%LOG%" echo [INFO] Starting "%AUTH_SERVICE%"
net start "%AUTH_SERVICE%" >> "%LOG%" 2>&1
)
:: Build list of VMX files
set "LIST=%TEMP%\vmx_boot_list_RESUME.txt"
dir /s /b /a:-d "%ROOT%\*.vmx" > "%LIST%" 2>nul
set "COUNT=0"
for /f "usebackq delims=" %%F in ("%LIST%") do (
set /a COUNT+=1
set "VMX=%%~fF"
set "VMDIR=%%~dpF"
echo.
echo === Cleaning & Starting: %%~nxF ===
echo DIR: "!VMDIR!"
rem 1) Remove stale suspend and lock files to avoid "Resuming..." state
if exist "!VMDIR!*.vmss" (
echo - Removing suspend state: "!VMDIR!*.vmss"
del /f /q "!VMDIR!*.vmss" >> "%LOG%" 2>&1
)
for /d %%L in ("!VMDIR!*.lck") do (
echo - Removing lock dir: "%%~fL"
rd /s /q "%%~fL" >> "%LOG%" 2>&1
)
rem 2) Start VM (Workstation target, headful so console can open)
echo - Starting via vmrun...
"%VMRUN%" -T ws start "!VMX!" >> "%LOG%" 2>&1
if errorlevel 1 (
echo -> start failed, will still open console
) else (
echo -> started
)
rem 3) Open console window
start "" "%VMGUI%" "!VMX!"
if not "%DELAY%"=="" timeout /t %DELAY% /nobreak >nul
)
echo.
echo Done. Attempted: %COUNT% VM(s). Log: "%LOG%"
type "%LOG%"
exit /b 0