I suggest to use this batch file for the VMware Workstation installation and update task:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "AppFileName=vmware.exe"
set "AppMinVersion=16.1.0.683"
set "AppName=VMware Workstation"
for /F "skip=1 tokens=2*" %%I in ('%SystemRoot%\System32\reg.exe QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\%AppFileName%" /ve 2^>nul') do if "%%I" == "REG_SZ" (
if not exist "%%J" (
echo %AppName% is registered to be installed in the folder:
echo(
echo "%%~dpJ"
echo(
echo But the file %AppFileName% does not exist.
echo(
echo Installing %AppName% ...
echo(
goto InstallVMware
)
set "AppFullName=%%J"
goto GetVersion
)
echo %AppName% is not installed and registered. Installing it ...
echo(
goto InstallVMware
:GetVersion
set "EscapedFileName=%AppFullName:\=\\%"
set "EscapedFileName=%EscapedFileName:'=\'%"
for /F "usebackq delims=" %%I in (`%SystemRoot%\System32\wbem\wmic.exe DataFile where "Name='%EscapedFileName%'" GET Version /VALUE 2^>nul`) do for /F "tokens=1* delims==" %%J in ("%%I") do set "VersionVMware=%%K" & goto CheckVersion
echo ERROR: Failed to determine version of installed %AppName% executable:
echo(
echo "%AppFullName%"
echo(
echo Please report this error to ... for a manual investigation.
echo(
echo There is done nothing regarding to %AppName% installation.
pause
goto EndBatch
:CheckVersion
for /F "tokens=1-4 delims=." %%G in ("%VersionVMware%") do set "VersionMajor=%%G" & set "VersionMinor=%%H" & set "VersionPatch=%%I" & set "VersionBuild=%%J"
for /F "tokens=1-4 delims=." %%G in ("%AppMinVersion%") do set "MinVersionMajor=%%G" & set "MinVersionMinor=%%H" & set "MinVersionPatch=%%I" & set "MinVersionBuild=%%J"
rem For the following version number comparisons is expexted that the version
rem string does not contain numbers with leading zeros like 08 or 009 or 014
rem as such numbers would be interpreted as octal numbers by command IF.
if %VersionMajor% LSS %MinVersionMajor% goto UpdateVMware
if %VersionMajor% GTR %MinVersionMajor% goto NoInstall
if %VersionMinor% LSS %MinVersionMinor% goto UpdateVMware
if %VersionMinor% GTR %MinVersionMinor% goto NoInstall
if %VersionPatch% LSS %MinVersionPatch% goto UpdateVMware
if %VersionPatch% GTR %MinVersionPatch% goto NoInstall
if %VersionBuild% LSS %MinVersionBuild% goto UpdateVMware
:NoInstall
echo %AppName% is already installed in version %VersionVMware%.
goto EndBatch
:UpdateVMware
echo %AppName% is installed in version %VersionVMware%.
echo An update is necessary, installing it ...
echo(
:InstallVMware
echo The installation of %AppName% %AppMinVersion% takes some minutes.
echo Please don't interrupt the installation process!
echo(
"%~dp0..\downloads\VMware-workstation-full-16.1.0-17198959.exe" /s /v /qn EULAS_AGREED=1 AUTOSOFTWAREUPDATE=0 DATACOLLECTION=0
:EndBatch
endlocal
The batch file first checks the application registration of VMware Workstation to find out if it is installed at all and in which folder vmware.exe
is installed on the current machine. The folder %ProgramFiles(x86)%\VMware\VMware Workstation
is just the default installation folder of VMware Workstation. It can be installed to any other folder during a manual installation.
If vmware.exe
is registered as installed application, the batch file checks next if the executable really still exists in registered installation folder. Otherwise the installation is corrupt and a new installation is necessary to fix this issue.
Next the batch file determines the version of vmware.exe
. That could fail if there is one or more commas in path which is very unusual, but nevertheless not impossible. In this case the user running the batch file should report this issue to somebody for a manual investigation.
The version of installed VMware Workstation is split up on the dots. Then is compared the version of installed VMware Workstation with the version which should be installed with the batch file. There is just an information output on installed VMware Workstation is already of expected version 16.1.0.683 or even a newer version.
Otherwise the installation is started with the parameters defined by you to update the existing installation or first time install VMware Workstation or fix the corrupted installation.
Note: The path of the batch file referenced with %~dp0
always ends with a backslash. For that reason never concatenate %~dp0
with an additional backlash with a file, folder or wildcard pattern as this results in \\
in finally expanded argument string which the Windows file management must correct back to \
before passing the argument string to the file system.
To understand the commands used and how they work, open a command prompt window, execute there the following commands, and read the displayed help pages for each command, entirely and carefully.
call /?
... explains how to reference batch file arguments as done with %~dp0
echo /?
endlocal /?
for /?
goto /?
if /?
reg /?
reg query /?
set /?
setlocal /?
wmic /?
wmic datafile /?
wmic datafile get /?
See also:
Read the Microsoft documentation about Using command redirection operators for an explanation of 2>nul
. The redirection operator >
must be escaped with caret character ^
on FOR command line to be interpreted as literal character when Windows command interpreter processes this command line before executing command FOR which starts in background with %ComSpec% /c
one more command process and passes the command line as argument strings to this command process.