cls
:ks
@echo off
CLS
color 0a
Title █████ VMware 12.5.6-5528349 绿色精简中文版 by wxdjs 2017.06.10 █████

set vmbit=
if /i %PROCESSOR_IDENTIFIER:~0,3% equ x86 (
    echo VMware11不支持32位操作系统,按任意键退出
    pause>nul
    goto EX
) else (
    set vmbit=64
)

echo 提示:最好在安装之前,先运行一下"!)卸载VMware.cmd"文件,以免旧版本干扰新版本安装
echo.
echo 注意:
echo 运行此批处理文件后,安装过程持续十几秒钟,并将跳出VMware服务安装窗口.
echo 如果窗口一闪而过,说明安装过程中出了错误.
echo 未正确安装VMware将导致虚拟机运行出错.
echo 请先排除故障后再次运行"!)安装VMware.cmd"批处理文件进行安装.
echo.
echo 注意: 虚拟打印机功能、共享虚拟机和远程访问服务(Hostd服务)
echo       请仔细看子功能菜单说明。
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 12.5.6-5528349 绿色精简中文版,请稍后...
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 USB Arbitration Service" (md "%AllUsersProfile%\VMware\VMware USB Arbitration Service" >nul)

cd /d "%~dp0"
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

echo 添加注册表项目...
regedit /s "%cd%\vm64.reg"
reg query "HKLM\SOFTWARE\Wow6432Node\VMware, Inc." >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.\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)

ver|find "6.1">nul && (
copy /y vmci\vmci.cat .\ >nul
copy /y vmci\vmci.inf .\ >nul
copy /y vmci\vmci.sys .\ >nul
copy /y vmci\vsock.sys .\ >nul
copy /y vmci\vsocklib_x86.dll .\ >nul
copy /y vmci\vsocklib_x64.dll .\ >nul
)
ver|find "6.1">nul || (
copy /y vmci\vmci.cat_win8 .\vmci.cat >nul
copy /y vmci\vmci.inf_win8 .\vmci.inf >nul
copy /y vmci\vmci.sys_win8 .\vmci.sys >nul
copy /y vmci\vsock.sys_win8 .\vsock.sys >nul
copy /y vmci\vsocklib_x86.dll_win8 .\vsocklib_x86.dll >nul
copy /y vmci\vsocklib_x64.dll_win8 .\vsocklib_x64.dll >nul
)

move /y vsocklib_x64.dll "%WinDir%\SysWOW64\vsocklib.dll" >nul 2>> install.log
move /y vsocklib_x86.dll "%WinDir%\System32\vsocklib.dll" >nul 2>> install.log


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 "%AppData%\VMware\config.ini" (copy /y config.ini "%AppData%\VMware\" >nul 2>> install.log)
if not exist "%AllUsersProfile%\VMware\VMware Workstation\config.ini" (copy /y config.ini "%AllUsersProfile%\VMware\VMware Workstation\" >nul 2>> install.log)
copy /y settings.ini "%AllUsersProfile%\VMware\VMware Workstation\" >nul
copy /y vnetinst.dll "%WinDir%\System32\" >nul 2>> install.log
copy /y vnetlib64.dll "%WinDir%\System32\" >nul 2>> install.log
copy /y vsock.sys "%WinDir%\system32\drivers\" >nul 2>> install.log
echo.

echo 注册所需的DLL文件...
regsvr32 /s vmappcfg.dll
regsvr32 /s vmappsdk.dll
regsvr32 /s vmdbCOM.dll
regsvr32 /s elevated.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 安装授权服务 ...
start /wait vnetlib.exe -- install authd
start /wait vnetlib.exe -- start authd
net start VMAuthdService >nul 2>nul
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMAuthdService >nul 2>nul||(sc create VMAuthdService  start= auto binpath= "%cd%\vmware-authd.exe"  depend= "vmx86/winmgmt" displayname= "VMware Authorization Service"&&net start VMAuthdService >nul 2>nul)
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMAuthdService >> 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