cls
:ks
@echo off
CLS
color 0a
Title █████VMware 11.1.0 绿色精简中文版█████

set vmbit=
if "%PROCESSOR_ARCHITECTURE%" neq "x86" set vmbit=64

echo 提示:最好在安装之前,先运行一下"!)卸载VMware.cmd"文件,以免旧版本干扰新版本安装
echo.
echo 注意:
echo 运行此批处理文件后,安装过程持续十几秒钟,并将跳出VMware服务安装窗口.
echo 如果窗口一闪而过,说明安装过程中出了错误.
echo 未正确安装VMware将导致虚拟机运行出错.
echo 请先排除故障后再次运行"!)安装VMware.cmd"批处理文件进行安装.
echo.
echo 按任意键继续安装VMware&pause>nul

reg query "HKLM\SOFTWARE\VMware, Inc." >nul 2> install.log || reg query "HKLM\SOFTWARE\Wow6432Node\VMware, Inc." >nul 2>> install.log&&(echo.&echo  系统中已经安装了VMware,请先卸载干净并重启电脑,按任意键跳转到卸载批处理!!!&pause>nul&&call "!)卸载VMware.cmd"&goto ks)
cls
net user %username% >nul 2>nul
if %errorlevel% neq 0 goto dnuser
net user %USERNAME% | find "Administrators" || goto prompt
goto stins
:dnuser
net user %username% /domain | find "Domain Admins" || goto prompt
:stins
echo ................
echo 正在安装VMware 11.1.0 绿色精简中文版,请稍后...
echo ................
echo.
echo 创建目录 >> install.log
if not exist "%AppData%\VMware" (md "%AppData%\VMware" >nul)
echo .
if not exist "%AppData%\VMware" (echo.&echo 创建目录失败,请关闭杀毒软件或者HIPS后再重新安装VMware&pause>nul&exit)
if not exist "%AllUsersProfile%\VMware" (md "%AllUsersProfile%\VMware" >nul 2>> install.log)
if not exist "%AllUsersProfile%\VMware\VMware Workstation" (md "%AllUsersProfile%\VMware\VMware Workstation" >nul 2>> install.log)
if not exist "%AllUsersProfile%\VMware\VMware Player" (md "%AllUsersProfile%\VMware\VMware Player" >nul)
if not exist "%AllUsersProfile%\VMware\VMware USB Arbitration Service" (md "%AllUsersProfile%\VMware\VMware USB Arbitration Service" >nul)

echo. >> install.log
echo 添加注册表 >> install.log
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmware.exe" /ve /d "%cd%\\vmware.exe" /f >nul
if %errorlevel% neq 0 echo 注册表写入失败,请使用右键-以管理员身份运行此批处理文件安装VMware&pause>nul&exit
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmware.exe" /v Path /t REG_SZ /d "%cd%\\" /f >nul
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmplayer.exe" /ve /d "%cd%\\vmplayer.exe" /f >nul
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmplayer.exe" /v Path /t REG_SZ /d "%cd%\\" /f >nul

cd /d "%~dp0"
echo 添加注册表项目...
regedit /s "%cd%\vm64.reg"
reg query "HKLM\SOFTWARE\Wow6432Node\VMware, Inc.\Installer" >nul 2>> install.log||(echo.&echo 注册表文件vm64.reg导入失败,请关闭杀毒软件或者HIPS后再重新安装VMware&rd /s /q "%AppData%\VMware"&rd /s /q "%AllUsersProfile%\VMware"&pause>nul&exit)
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\VMware, Inc.\Installer\VMware Workstation\Features" /v core /t REG_SZ /d "%cd%" /f >nul
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\VMware, Inc.\VMware Player" /v InstallPath /t REG_SZ /d "%cd%\\" /f >nul
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\VMware, Inc.\VMware Player" /v InstallPath64 /t REG_SZ /d "%cd%\x64\\" /f >nul
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\VMware, Inc.\VMware Workstation" /v InstallPath /t REG_SZ /d "%cd%\\" /f >nul
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\VMware, Inc.\VMware Workstation" /v InstallPath64 /t REG_SZ /d "%cd%\x64\\" /f >nul
echo 安装VC运行库 >> install.log
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{4B6C7001-C7D6-3710-913E-5BC23FCE91E6} >nul 2>nul||reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5FCE6D76-F5DC-37AB-B2B8-22AB8CEDB1D4} >nul 2>nul||(echo.&echo 正在安装VC++2008......&start /wait vc08x64.exe /q&&start /wait vc08x86.exe /q)

copy /y vmci\* .\ >nul
move /y vsocklib32.dll "%WinDir%\SysWOW64\vsocklib.dll" >nul 2>> install.log
move /y vsocklib64.dll "%WinDir%\System32\vsocklib.dll" >nul

echo.

str.exe preferences.ini 0 0 /R /asc:"VMwareDir" /asc:"%cd%" /A >nul 2>> install.log
str.exe environments.xml 0 0 /R /asc:"VMwareDir" /asc:"%cd%" /A >nul 2>> install.log
echo 复制文件...
echo.
if not exist "%AppData%\VMware\preferences.ini" (copy /y preferences.ini "%AppData%\VMware\" >nul 2>> install.log)
if not exist "%AllUsersProfile%\VMware\VMware Workstation\config.ini" (copy /y vmconfig.ini "%AllUsersProfile%\VMware\VMware Workstation\config.ini" >nul 2>> install.log)
copy /y settings.ini "%AllUsersProfile%\VMware\VMware Player\" >nul
copy /y settings.ini "%AllUsersProfile%\VMware\VMware Workstation\" >nul
if not exist "%AllUsersProfile%\VMware\VMware Player\config.ini" (copy /y vpconfig.ini "%AllUsersProfile%\VMware\VMware Player\config.ini" >nul)
copy /y vnetinst.dll "%WinDir%\System32\" >nul 2>> install.log
copy /y vnetlib64.dll "%WinDir%\System32\" >nul 2>> install.log
copy /y vmci\vsock.sys "%WinDir%\system32\drivers\" >nul 2>> install.log
echo.

echo 注册所需的DLL文件...
regsvr32 /s vmappcfg.dll
regsvr32 /s vmappsdk.dll
regsvr32 /s vmdbCOM.dll

echo.
echo 创建 __vmware_user__ 用户组 >> install.log
echo 创建 __vmware_user__ 用户组 ...
net localgroup users __vmware_user__ /del >nul 2>nul
net localgroup __vmware__ /del >nul 2>nul
net user __vmware_user__ /del >nul 2>nul
echo.
net localgroup __vmware__ /add /comment:"VMware User Group" >nul 2>> install.log
if %errorlevel% neq 0 echo 用户组创建失败,请关闭杀毒软件或者HIPS后再重新安装VMware&pause>nul&exit

echo 安装VM基本服务 ...
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VMware\Performance" /v Library /t REG_SZ /d "%cd%\vmPerfmon.dll" /f >nul

sc create vsock type= kernel start= boot binpath= "%WinDir%\system32\drivers\vsock.sys" Group= "System Bus Extender" displayname= "vSockets Driver"
if not exist "%WinDir%\System32\Drivers\vsock.sys" copy /y vsock.sys "%WinDir%\System32\Drivers\"

net stop vmx86 >nul 2>> install.log
sc delete vmx86 >nul 2>> install.log
start /wait vnetlib%vmbit%.exe -- install vmx86
start /wait vnetlib%vmbit%.exe -- start vmx86

net stop vmx86 >nul 2>> install.log
net start vmx86 >nul 2>> install.log
if %errorlevel% neq 0 echo 服务启动失败,请关闭杀毒软件或者HIPS后,再运行"卸载VMware.cmd"清理安装记录,然后重新安装VMware&pause>nul&exit

net stop vmci >nul 2>> install.log
sc delete vmci >nul 2>> install.log

DrvInst64.exe installRootDriver HWND "ROOT\VMWVMCIHOSTDEV" .\vmci.inf "" >nul

vnetlib%vmbit%.exe -- install vmci
net start vsock >nul 2>> install.log

echo.
echo 创建快捷方式
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""AllUsersDesktop"") & ""\VMware.lnk""):b.TargetPath=""%~dp0vmware.exe"":b.WorkingDirectory=""%~dp0\"":b.Save:close") >nul
echo.
echo.
echo.
echo 请注意上面错误提示,若安装后无法正常运行VMware,
echo 请把上面的错误提示复制下来反馈到我的帖子里,谢谢.
echo 按任意键继续安装VMware服务.
pause >nul

:ST
CALL "安装服务.cmd"
:EX
exit

:prompt
echo ..................
echo 提示:
echo 登录系统的并非是Administrators管理员组的用户,
echo 安装VMware精简版请切换到管理员用户进行安装!
echo 在管理员用户下使用右键--以管理员身份运行
echo 此批处理文件进行安装.
echo ..................
pause
goto :EX