@ECHO OFF & TITLE VMware Workstation 16.1.0.17198959 by Anson [%~nx0] & PUSHD %~dp0
::--------------------------------------------------------------------------------------------------------------------------::
:: 最后更新： 批处理 2020/11/21    注册表 2020/11/21    文件 2020/11/21

::最基础的服务：vmx86 vmci VMAuthdService
::---------------------------------------------------- 自动提升运行权限 ----------------------------------------------------::
%Windir%\System32\FLTMC.exe >nul 2>&1 || (
    ECHO CreateObject^("Shell.Application"^).ShellExecute "%~f0", "%1", "", "runas", 1 > "%TEMP%\AdminRun.vbs"
    ECHO CreateObject^("Scripting.filesystemobject"^).DeleteFile ^(WScript.ScriptFullName^) >> "%TEMP%\AdminRun.vbs"
    %Windir%\System32\CSCRIPT.exe //Nologo "%TEMP%\AdminRun.vbs"
    Exit /b
)
::--------------------------------------------------------------------------------------------------------------------------::

::------------------------------------------------------ 设置运行环境 ------------------------------------------------------::
FOR /f "tokens=3" %%i in ('REG.exe query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuild ^| FIND.exe /i "CurrentBuild"') do SET "OSBuild=%%i"
IF /i "%PROCESSOR_ARCHITECTURE%" EQU "AMD64" (SET "ARCH=x64" & SET "vmbit=64") ELSE (SET "ARCH=%PROCESSOR_ARCHITECTURE%")
IF %OSBuild% LSS 9200 (ECHO. & ECHO 操作系统的版本过低，按任意键退出... & PAUSE>nul & Exit)
IF /i %ARCH% NEQ x64 (ECHO. & ECHO 请在64位系统下使用，按任意键退出... & PAUSE>nul & Exit)

SET "PATH=%CD%\_Data\CMD;%PATH%"
SET "DataPATH=%CD%\_Data"
::--------------------------------------------------------------------------------------------------------------------------::

::------------------------------------------------------- 条件呼叫 --------------------------------------------------------::
IF EXIST "%DataPATH%\#VIP.txt" TYPE "%DataPATH%\#VIP.txt"
IF /i "%1" EQU "Harduninst" goto :Uninst
IF /i "%1" EQU "NetWork" goto :%1
IF /i "%1" EQU "Uninst" goto :%1
IF /i "%1" NEQ "Silent" PAUSE
::--------------------------------------------------------------------------------------------------------------------------::

:Begin
::----------------------------------------------------- 设置文件夹权限 -----------------------------------------------------::
IF /i %~d0 EQU %SystemDrive% (iCACLS.exe "%CD%" /reset && SetACL.exe -on "%CD%" -ot file -actn ace -ace "n:everyone;p:change")
::--------------------------------------------------------------------------------------------------------------------------::

::------------------------------------------- 复制文件到系统文件夹/解压缩公用文件 ------------------------------------------::
IF %OSBuild% GEQ 9200 (SET "NTv=NT10") ELSE (SET "NTv=NT6")
7za.exe x -y "%DataPATH%\Data_AllUsers.7z" -o"%AllUsersProfile%"
XCOPY.exe /y /f "%AllUsersProfile%\VMware\VMware Workstation\config.ini" "%AppData%\VMware\" >nul 2>&1
7za.exe x -y "%DataPATH%\CF64_VMware.Drivers_%NTv%.7z" -o"%CommonProgramFiles%"

ROBOCOPY.exe "%DataPATH%\System32" "%Windir%\System32" "*140*.dll" /xo>nul
ROBOCOPY.exe "%DataPATH%\SysWOW64" "%Windir%\SysWOW64" "*140.dll" /xo>nul
::--------------------------------------------------------------------------------------------------------------------------::

::---------------------------------------------- 处理注册表/注册DLL/创建服务 -----------------------------------------------::
ECHO. & ECHO 添加注册表^(基本项^)....
REGEDIT.exe /s "%CD%\_Data\VMware_Base_16.1.0.reg"
REG.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmware.exe" /ve /d "%CD%\vmware.exe" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmware.exe" /v Path /t REG_SZ /d "%CD%\\" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmplayer.exe" /ve /d "%CD%\vmplayer.exe" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmplayer.exe" /v Path /t REG_SZ /d "%CD%\\" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\WOW6432Node\VMware, Inc.\VMware Workstation" /v InstallPath64 /t REG_SZ /d "%CD%\x64\\" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\WOW6432Node\VMware, Inc.\VMware Workstation" /v InstallPath /t REG_SZ /d "%CD%\\" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\WOW6432Node\VMware, Inc.\VMware Player" /v InstallPath64 /t REG_SZ /d "%CD%\x64\\" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\WOW6432Node\VMware, Inc.\VMware Player" /v InstallPath /t REG_SZ /d "%CD%\\" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{95096479-66A1-454B-9378-234DF3B31727}" /v "UninstallString" /t REG_SZ /d "%CD%\#Uninst.cmd" /f
REG.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{95096479-66A1-454B-9378-234DF3B31727}" /v "DisplayIcon" /t REG_SZ /d "%CD%\vmware.exe" /f


ECHO. & ECHO 添加注册表^(文件图标项^)....
REGEDIT.exe /s "%CD%\_Data\VMware_Assoc.reg"
REG.exe add "HKLM\SOFTWARE\Classes\VMware.Document\DefaultIcon" /ve /t REG_SZ /d "%CD%\ico\config.ico,0" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.Document\shell\Open\command" /ve /t REG_SZ /d "\"%CD%\vmware.exe\" -t \"%%1\"" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.Snapshot\DefaultIcon" /ve /t REG_SZ /d "%CD%\ico\snapshot.ico,0" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.SnapshotMetadata\DefaultIcon" /ve /t REG_SZ /d "%CD%\ico\generic.ico,0" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.SnapshotMetadata\shell\Open\command" /ve /t REG_SZ /d "\"%CD%\vmware.exe\" -t \"%%1\"" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.SuspendState\DefaultIcon" /ve /t REG_SZ /d "%CD%\ico\suspend.ico,0" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.TeamConfiguration\DefaultIcon" /ve /t REG_SZ /d "%CD%\ico\generic.ico,0" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.TeamConfiguration\shell\Open\command" /ve /t REG_SZ /d "\"%CD%\vmware.exe\" -t \"%%1\"" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.VirtualDisk\DefaultIcon" /ve /t REG_SZ /d "%CD%\ico\vd.ico,0" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.VMBios\DefaultIcon" /ve /t REG_SZ /d "%CD%\ico\generic.ico,0" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.VMBios\shell\Open\command" /ve /t REG_SZ /d "\"%CD%\vmware.exe\" -t \"%%1\"" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.VMPolicy\DefaultIcon" /ve /t REG_SZ /d "%CD%\ico\generic.ico,0" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.VMPolicy\shell\Open\command" /ve /t REG_SZ /d "\"%CD%\vmware.exe\" -t \"%%1\"" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.VMTeamMember\DefaultIcon" /ve /t REG_SZ /d "%CD%\ico\generic.ico,0" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.VMTeamMember\shell\Open\command" /ve /t REG_SZ /d "\"%CD%\vmware.exe\" -t \"%%1\"" /f >nul 2>&1


ECHO. & ECHO 添加注册表^(右键菜单项^)....
REG.exe add "HKLM\SOFTWARE\Classes\VMware.VirtualDisk\ShellEx\ContextMenuHandlers\VMDiskMenuHandler" /ve /t REG_SZ /d "{271DC252-6FE1-4D59-9053-E4CF50AB99DE}" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\VMware.VirtualDisk\ShellEx\ContextMenuHandlers\VMDiskMenuHandler64" /ve /t REG_SZ /d "{E4D28EDC-8C0B-43EE-9E7D-C8A8682334DC}" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{271DC252-6FE1-4D59-9053-E4CF50AB99DE}" /ve /t REG_SZ /d "VMDiskMenuHandler Class" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{271DC252-6FE1-4D59-9053-E4CF50AB99DE}\InprocServer32" /ve /t REG_SZ /d "%CD%\vmdkShellExt.dll" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{271DC252-6FE1-4D59-9053-E4CF50AB99DE}\InprocServer32" /v "ThreadingModel" /t REG_SZ /d "Apartment" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{0FCBEDD8-A1E5-4D75-9E21-C744577E36DB}" /ve /t REG_SZ /d "Shell extension thunker class" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{0FCBEDD8-A1E5-4D75-9E21-C744577E36DB}\LocalServer32" /ve /t REG_SZ /d "\"%CD%\vmware-shell-ext-thunker.exe\"" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{0FCBEDD8-A1E5-4D75-9E21-C744577E36DB}\TypeLib" /ve /t REG_SZ /d "{FA607407-E944-4381-8F79-B01080035288}" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Wow6432Node\Interface\{7264C314-E7F0-47F6-BDEA-CDC806DA2CD1}" /ve /t REG_SZ /d "IContextMenuThunker" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Wow6432Node\Interface\{7264C314-E7F0-47F6-BDEA-CDC806DA2CD1}\ProxyStubClsid32" /ve /t REG_SZ /d "{00020424-0000-0000-C000-000000000046}" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Wow6432Node\Interface\{7264C314-E7F0-47F6-BDEA-CDC806DA2CD1}\TypeLib" /ve /t REG_SZ /d "{FA607407-E944-4381-8F79-B01080035288}" /f
REG.exe add "HKLM\SOFTWARE\Classes\Wow6432Node\Interface\{7264C314-E7F0-47F6-BDEA-CDC806DA2CD1}\TypeLib" /v "Version" /t REG_SZ /d "1.0" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\TypeLib\{FA607407-E944-4381-8F79-B01080035288}\1.0" /ve /t REG_SZ /d "ShellExtThunker 1.0 Type Library" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\TypeLib\{FA607407-E944-4381-8F79-B01080035288}\1.0\0\win32" /ve /t REG_SZ /d "%CD%\vmware-shell-ext-thunker.exe" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Interface\{7264C314-E7F0-47F6-BDEA-CDC806DA2CD1}" /ve /t REG_SZ /d "IContextMenuThunker" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Interface\{7264C314-E7F0-47F6-BDEA-CDC806DA2CD1}\ProxyStubClsid32" /ve /t REG_SZ /d "{00020424-0000-0000-C000-000000000046}" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Interface\{7264C314-E7F0-47F6-BDEA-CDC806DA2CD1}\TypeLib" /ve /t REG_SZ /d "{FA607407-E944-4381-8F79-B01080035288}" /f >nul 2>&1
REG.exe add "HKLM\SOFTWARE\Classes\Interface\{7264C314-E7F0-47F6-BDEA-CDC806DA2CD1}\TypeLib" /v "Version" /t REG_SZ /d "1.0" /f >nul 2>&1
REGSVR32.exe /s "%CD%\%ARCH%\vmdkShellExt%vmbit%.dll"

REM environments.xml 这个文件在 VMware 15.1.0/15.0.2 中是包含完整路径的，而在 15.5.0 里面则是相对路径，所以不需要查找替换路径了。
REM COPY /y "%DataPATH%\environments.xml" "%CD%" && STR.exe environments.xml 0 0 /R /asc:"C:\Program Files (x86)\VMware\VMware Workstation" /asc:"%CD%" /A
REM XCOPY.exe /y /f "%DataPATH%\preferences.ini" "%AppData%\VMware\" && STR.exe "%AppData%\VMware\preferences.ini" 0 0 /R /asc:"C:\Program Files (x86)\VMware\VMware Workstation" /asc:"%CD%" /A


ECHO. & ECHO 注册所需的DLL文件...
REGSVR32.exe /s elevated.dll
REGSVR32.exe /s vmappcfg.dll
REGSVR32.exe /s vmappsdk.dll
REGSVR32.exe /s vmdbCOM.dll


ECHO. & ECHO 创建__vmware_user__用户组 ...
NET.exe localgroup users __vmware_user__ /del >nul 2>nul
NET.exe localgroup __vmware__ /del >nul 2>nul
NET.exe user __vmware_user__ /del >nul 2>nul
NET.exe localgroup __vmware__ /add /comment:"VMware User Group" >nul 2>nul


REM ECHO. & ECHO 安装VMware基本服务^(性能检测?^) ...
REM ::相关文件: vmPerfmon.dll vmPerfmon.h vmPerfmon.ini
REM REG.exe add "HKLM\SYSTEM\CurrentControlSet\services\VMware\Performance" /ve /t REG_SZ /d "" /f >nul 2>&1
REM REG.exe add "HKLM\SYSTEM\CurrentControlSet\services\VMware\Performance" /v "Close" /t REG_SZ /d "PerfmonClose" /f >nul 2>&1
REM REG.exe add "HKLM\SYSTEM\CurrentControlSet\services\VMware\Performance" /v "Collect" /t REG_SZ /d "PerfmonCollect" /f >nul 2>&1
REM REG.exe add "HKLM\SYSTEM\CurrentControlSet\services\VMware\Performance" /v "Open" /t REG_SZ /d "PerfmonOpen" /f >nul 2>&1
REM REG.exe add "HKLM\SYSTEM\CurrentControlSet\services\VMware\Performance" /v "PerfIniFile" /t REG_SZ /d "vmPerfmon.ini" /f >nul 2>&1
REM REG.exe add "HKLM\SYSTEM\CurrentControlSet\Services\VMware\Performance" /v "Library" /t REG_SZ /d "%CD%\vmPerfmon.dll" /f >nul 2>&1

::sc.exe [<servername>] create [<servicename>] [type= {own | share | kernel | filesys | rec | interact type= {own | share}}] [start= {boot | system | auto | demand | disabled | delayed-auto}] [error= {normal | severe | critical | ignore}] [binpath= <binarypathname>] [group= <loadordergroup>] [tag= {yes | no}] [depend= <dependencies>] [obj= {<accountname> | <objectname>}] [displayname= <displayname>] [password= <password>]
::tag= {yes | no}
::tag= {50 | ? | 47}
::error= {normal | severe | critical | ignore}
::error= {1      | 2      | 3        | 0}
::start= {boot | system | auto | demand | disabled | delayed-auto}
::start= {0    | 1      | 2    | 3      | 4        | delayed-auto}
::type= {own | share | kernel | filesys | rec | interact type= {own | share}}
::type= {16  | 32    | 1      | 2       |     | interact type= {own | share}}
ECHO. & ECHO 安装VMX86驱动服务 ^(VMware vmx86 driver^)...
COPY /y "%DataPATH%\System32\drivers\vmx86.sys" "%WinDir%\System32\drivers\"
SC.exe create vmx86 type= kernel start= auto error= ignore binpath= "%Windir%\System32\drivers\vmx86.sys" Group= "Extended Base" displayname= "VMware vmx86" Tag= no
SC.exe Description "vmx86" "VMware vmx86 driver"
SC.exe start vmx86>nul
REM START /wait vnetlib%vmbit%.exe -- install vmx86
REM START /wait vnetlib%vmbit%.exe -- start vmx86

ECHO. & ECHO 安装VMCI驱动服务 ^(VMware VMCI bus driver^)...
IF %OSBuild% GEQ 9200 (SET "NTv=Win8") ELSE (SET "NTv=Vista")
DrvInst64.exe installRootDriver HWND "ROOT\VMWVMCIHOSTDEV" "%CommonProgramFiles%\VMware\Drivers\vmci\device\%NTv%\vmci.inf" ""
START /wait vnetlib%vmbit%.exe -- install vmci
START /wait vnetlib%vmbit%.exe -- start vmci

ECHO. & ECHO 安装授权服务 ^(VMware Authorization Service^)...
SC.exe create VMAuthdService type= own start= auto obj= LocalSystem depend= "vmx86/vmci/winmgmt" error= normal binpath= "\"%CD%\vmware-authd.exe\"" displayname= "VMware Authorization Service"
SC.exe Description "VMAuthdService" "Authorization and authentication service for starting and accessing virtual machines."
SC.exe start VMAuthdService>nul
REM START /wait vnetlib.exe -- install authd
REM START /wait vnetlib.exe -- start authd


ECHO. & ECHO 安装磁盘映射驱动服务 ^(Vstor2 MntApi 2.0 driver^)...
COPY /y "%DataPATH%\SysWOW64\drivers\vstor2-x64.sys" "%WinDir%\SysWOW64\drivers\"
SC.exe create vstor2-mntapi20-shared type= kernel start= auto binpath= "SysWOW64\drivers\vstor2-x64.sys" displayname= "Vstor2 MntApi 2.0 Driver (shared)"
SC.exe start vstor2-mntapi20-shared>nul


ECHO. & ECHO 安装增强型键盘驱动服务^(VMware Enhanced keyboard driver)^...
InfDefaultInstall.exe "%CommonProgramFiles%\VMware\Drivers\vmkbd\Win7\vmkbd.inf"
FOR /f "tokens=3" %%i in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E96B-E325-11CE-BFC1-08002BE10318}" /v "UpperFilters"') do (ECHO %%i| FIND.exe /i "vmkbd3">nul 2>&1 || SET "UpperFilters=%%i\0vmkbd3")
IF DEFINED UpperFilters REG.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E96B-E325-11CE-BFC1-08002BE10318}" /v UpperFilters /t REG_MULTI_SZ /d "%UpperFilters%" /f


ECHO. & ECHO 安装USB设备支持服务(VMware USB arbitration Service - 客户机的USB控制器+本驱动，使鼠标光标在客户机与主机之间无痕切换，而不需要按快捷键 Ctrl+Alt 等)...
REG.exe add "HKLM\SOFTWARE\Wow6432Node\VMware, Inc.\VMware USB" /v InstallPath /t REG_SZ /d "%CommonProgramFiles(x86)%\VMware\USB\\" /f
IF %OSBuild% GEQ 9200 (SET "NTv=Win8") ELSE (SET "NTv=Win7")
InfDefaultInstall.exe "%CommonProgramFiles%\VMware\Drivers\hcmon\Win7\hcmon.inf"
Devcon%vmbit%.exe dp_add "%CommonProgramFiles%\VMware\Drivers\vmusb\%NTv%\vmusb.inf"

7za.exe x -y "%DataPATH%\CF32_VMware.USB.7z" -o"%CommonProgramFiles(x86)%"
"%CommonProgramFiles(x86)%\VMware\USB\vnetlib%vmbit%.exe" -- install hcmon
"%CommonProgramFiles(x86)%\VMware\USB\vnetlib%vmbit%.exe" -- install usb
SC.exe create VMUSBArbService start= auto depend= winmgmt binpath= "\"%CommonProgramFiles(x86)%\VMware\USB\vmware-usbarbitrator%vmbit%.exe\"" displayname= "VMware USB Arbitration Service"
SC.exe Description "VMUSBArbService" "Arbitration and enumeration of USB devices for virtual machines"
IF %OSBuild% GEQ 9200 REG.exe add "HKLM\SYSTEM\CurrentControlSet\services\VMUSBArbService" /v WOW64 /t REG_DWORD /d "0x0000014c" /f >nul 2>&1
IF %OSBuild% LSS 9200 REG.exe add "HKLM\SYSTEM\CurrentControlSet\services\VMUSBArbService" /v WOW64 /t REG_DWORD /d "0x00000001" /f >nul 2>&1
SC.exe start VMUSBArbService>nul


IF /i "%1" EQU "NetWork" CALL :NetWork

REM ECHO. & ECHO 创建快捷方式...
START /min mshta.exe 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")
::--------------------------------------------------------------------------------------------------------------------------::


::-------------------------------------------------------- 结束.退出 -------------------------------------------------------::
:AllTheEnd
CALL :iconRefresh
SET "Tip=安装完成"
IF /i "%1" EQU "Uninst" SET "Tip=卸载完成，建议重启机器"
(FOR /l %%t in (6,-1,0) DO (CLS & TYPE "%DataPATH%\#VIP.txt" 2>nul & ECHO. & ECHO ^> %Tip%，%%t 秒后退出... & CHOICE.exe /t 1 /d y /n >nul)) & Exit
::------------------------------------------------------- All The End ------------------------------------------------------::




::---------------------------------------------------------- 卸载 ----------------------------------------------------------::
:Uninst
CLS & COLOR 4F
TITLE VMware Workstation Uninstall [%~nx0]

IF /i "%1" EQU "Harduninst" (
    ECHO. & ECHO 卸载会彻底删除包括用户配置文件在内的所有文件，
    ECHO. & ECHO 退出请点击窗口右上角的[X]，
    ECHO. & ECHO 继续请按任意键...
) ELSE (
    ECHO. & ECHO 卸载会保留用户配置文件，
    ECHO. & ECHO 准备就绪，按任意键继续...
)
PAUSE>nul


REM CLS & ECHO. & ECHO 删除快捷方式...
Start /min mshta.exe VBScript:Execute("On Error Resume Next:Set a=CreateObject(""WScript.Shell""):Set b=CreateObject(""Scripting.FileSystemObject"").DeleteFile(a.SpecialFolders(""AllUsersDesktop"") & ""\VMware.lnk""):b.Save:close")

TASKKILL.exe /f /im "VMWare.exe" >nul 2>&1
TASKKILL.exe /f /im "vmnat.exe" >nul 2>&1
TASKKILL.exe /f /im "vmnetcfg.exe" >nul 2>&1
TASKKILL.exe /f /im "VMnetDHCP.exe" >nul 2>&1
TASKKILL.exe /f /im "vmware-vmx.exe" >nul 2>&1
TASKKILL.exe /f /im "vmware-vmx-stats.exe" >nul 2>&1
TASKKILL.exe /f /im "vmware-vmx-debug.exe" >nul 2>&1
TASKKILL.exe /f /im "vixDiskMountServer.exe" >nul 2>&1


vnetlib%vmbit%.exe -- stop authd >nul 2>&1
vnetlib%vmbit%.exe -- uninstall authd >nul 2>&1
SC.exe stop VMwareHostd >nul 2>&1 && SC.exe delete VMwareHostd >nul 2>&1
SC.exe stop VMAuthdService >nul 2>&1 && SC.exe delete VMAuthdService >nul 2>&1

vnetlib%vmbit%.exe -- stop dhcp >nul 2>&1
vnetlib%vmbit%.exe -- uninstall dhcp >nul 2>&1
vnetlib%vmbit%.exe -- stop nat >nul 2>&1
vnetlib%vmbit%.exe -- uninstall nat >nul 2>&1
vnetlib%vmbit%.exe -- stop bridge >nul 2>&1
vnetlib%vmbit%.exe -- uninstall bridge >nul 2>&1
vnetlib%vmbit%.exe -- stop userif >nul 2>&1
vnetlib%vmbit%.exe -- uninstall userif >nul 2>&1
vnetlib%vmbit%.exe -- stop adapter >nul 2>&1
vnetlib%vmbit%.exe -- uninstall adapter >nul 2>&1
RUNDLL32.exe vnetlib%vmbit%.dll,VNL_RemoveAllNetworkDevices

SC.exe stop VMUSBArbService >nul 2>&1 && SC.exe delete VMUSBArbService >nul 2>&1
vnetlib%vmbit%.exe -- stop usb
vnetlib%vmbit%.exe -- uninstall usb
vnetlib%vmbit%.exe -- stop hcmon >nul 2>&1
vnetlib%vmbit%.exe -- uninstall hcmon >nul 2>&1

SC.exe stop vstor2-mntapi20-shared >nul 2>&1 && SC.exe delete vstor2-mntapi20-shared >nul 2>&1

vnetlib%vmbit%.exe -- stop vmkbd >nul 2>&1
vnetlib%vmbit%.exe -- uninstall vmkbd >nul 2>&1
SC.exe stop vmkbd >nul 2>&1 && SC.exe delete vmkbd >nul 2>&1

vnetlib%vmbit%.exe -- stop vmparport >nul 2>&1
vnetlib%vmbit%.exe -- uninstall vmparport >nul 2>&1

devcon%vmbit%.exe remove "ROOT\VMWVMCIHOSTDEV" >nul 2>&1

vnetlib%vmbit%.exe -- stop vsock >nul 2>&1
SC.exe stop vsock >nul 2>&1 && SC.exe delete vsock >nul 2>&1

vnetlib%vmbit%.exe -- stop vmx86 >nul 2>&1
vnetlib%vmbit%.exe -- uninstall vmx86 >nul 2>&1

vnetlib%vmbit%.exe -- uninstall vmci


SC.exe stop "VMware NAT Service" >nul 2>&1 && SC.exe delete "VMware NAT Service" >nul 2>&1
SC.exe stop VMnetDHCP >nul 2>&1 && SC.exe delete VMnetDHCP >nul 2>&1
SC.exe stop VMnetAdapter >nul 2>&1 && SC.exe delete VMnetAdapter >nul 2>&1
SC.exe stop vmusb >nul 2>&1&& SC.exe delete vmusb >nul 2>&1
SC.exe stop VMnetBridge >nul 2>&1 && SC.exe delete VMnetBridge >nul 2>&1
SC.exe stop vmci >nul 2>&1 && SC.exe delete vmci >nul 2>&1

SC.exe delete "vstor2-mntapi20-shared" >nul 2>&1
SC.exe delete "VMparport" >nul 2>&1
SC.exe delete VMUSBArbService >nul 2>&1
SC.exe delete VMnetDHCP >nul 2>&1
SC.exe delete "VMware NAT Service" >nul 2>&1
SC.exe delete VMAuthdService >nul 2>&1
SC.exe delete VMnetuserif >nul 2>&1
SC.exe delete VMnetAdapter >nul 2>&1
SC.exe delete vmkbd >nul 2>&1
SC.exe delete vmx86 >nul 2>&1


ECHO. & ECHO 反注册DLL文件...
REGSVR32.exe /u /s "%CD%\elevated.dll"
REGSVR32.exe /u /s "%CD%\vmappcfg.dll"
REGSVR32.exe /u /s "%CD%\vmappsdk.dll"
REGSVR32.exe /u /s "%CD%\vmdbCOM.dll"
REGSVR32.exe /u /s "%CD%\vmdkShellExt.dll"
REGSVR32.exe /u /s "%CD%\x64\vmdkShellExt64.dll"
REGSVR32.exe /u /s "%CD%\VMware VIX\VixCOM.dll"
REGSVR32.exe /u /s "%CD%\VMware VIX\VixCOM64.dll"1


ECHO. & ECHO 清理注册表^(基本项^)....
REG.exe delete "HKCU\SOFTWARE\Wow6432Node\VMware, Inc." /f >nul 2>&1
REG.exe delete "HKCU\SOFTWARE\VMware, Inc." /f >nul 2>&1
REG.exe delete "HKCU\SOFTWARE\ThinPrint" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\ThinPrint" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\VMware, Inc." /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Drivers32" /f /v "VIDC.VMnc" >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmware.exe" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmplayer.exe" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /f /v "vmware-tray" >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run" /f /v "vmware-tray" >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Wow6432Node\VMware, Inc." /f >nul 2>&1
REG.exe delete "HKLM\SYSTEM\CurrentControlSet\Services\VMware" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{95096479-66A1-454B-9378-234DF3B31727}" /f >nul 2>&1


ECHO. & ECHO 清理注册表^(文件图标项^)....
REG.exe delete "HKLM\SOFTWARE\Classes\.nvram" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.ova" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.ovf" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.vmac" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.vmba" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.vmdk" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.vmpl" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.vmsd" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.vmsn" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.vmss" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.vmt" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.vmtm" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.vmx" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\.vmxf" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.Document" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.OVAPackage" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.OVFPackage" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.Snapshot" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.SnapshotMetadata" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.SuspendState" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.TeamConfiguration" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.VirtualDisk" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.VMBios" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.VMPolicy" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.VMTeamMember" /f >nul 2>&1


ECHO. & ECHO 清理注册表^(右键菜单项^)....
REG.exe delete "HKLM\SOFTWARE\Classes\VMware.VirtualDisk" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\TypeLib\{FA607407-E944-4381-8F79-B01080035288}" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\Interface\{7264C314-E7F0-47F6-BDEA-CDC806DA2CD1}" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{271DC252-6FE1-4D59-9053-E4CF50AB99DE}" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\Wow6432Node\CLSID\{0FCBEDD8-A1E5-4D75-9E21-C744577E36DB}" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Classes\Wow6432Node\Interface\{7264C314-E7F0-47F6-BDEA-CDC806DA2CD1}" /f >nul 2>&1


ECHO. & ECHO 删除相关文件...
RD /s /q "%CommonProgramFiles%\VMware" >nul 2>&1
RD /s /q "%CommonProgramFiles(x86)%\VMware" >nul 2>&1
RD /s /q "%CommonProgramFiles(x86)%\ThinPrint" >nul 2>&1
RD /s /q "%Windir%\inf\VMware" >nul 2>&1

DEL /f /q "%Windir%\system32\vmnc.dll" >nul 2>&1
DEL /f /q "%Windir%\system32\vmnat.exe" >nul 2>&1
DEL /f /q "%Windir%\system32\vmnetdhcp.exe" >nul 2>&1
DEL /f /q "%Windir%\system32\vmnetbridge.dll" >nul 2>&1
DEL /f /q "%Windir%\system32\vnetinst.dll" >nul 2>&1
DEL /f /q "%Windir%\system32\vnetlib*.dll" >nul 2>&1
DEL /f /q "%Windir%\system32\vsocklib.dll" >nul 2>&1
DEL /f /q "%Windir%\system32\drivers\vmci.sys" >nul 2>&1
DEL /f /q "%Windir%\system32\drivers\vmkbd.sys" >nul 2>&1
DEL /f /q "%Windir%\system32\drivers\vmx86.sys" >nul 2>&1
DEL /f /q "%Windir%\system32\drivers\vmusb.sys" >nul 2>&1
DEL /f /q "%Windir%\system32\drivers\vmnet*.sys" >nul 2>&1
DEL /f /q "%Windir%\system32\drivers\vmparport.sys" >nul 2>&1
DEL /f /q "%Windir%\system32\drivers\vsock.sys" >nul 2>&1

DEL /f /q "%Windir%\SysWOW64\vmnc.dll" >nul 2>&1
DEL /f /q "%Windir%\SysWOW64\vmnat.exe" >nul 2>&1
DEL /f /q "%Windir%\SysWOW64\vmnetdhcp.exe" >nul 2>&1
DEL /f /q "%Windir%\SysWOW64\vsocklib.dll" >nul 2>&1
DEL /f /q "%Windir%\SysWOW64\drivers\vstor2-x64.sys" >nul 2>&1

RD /s /q "%localAppdata%\VMware" >nul 2>&1
RD /s /q "%AllUsersProfile%\VMware" >nul 2>&1
RD /s /q "%Windir%\SysWOW64\Config\systemProfile\Appdata\Roaming\VMware" >nul 2>&1
IF /i "%1" EQU "Harduninst" RD /s /q "%AppData%\VMware" >nul 2>&1


ECHO. & ECHO 删除账户__vmware_user__...
NET.exe localgroup users __vmware_user__ /del >nul 2>&1
NET.exe user __vmware_user__ /del >nul 2>&1
ECHO. & ECHO 删除用户组__vmware__...
NET.exe localgroup __vmware__ /del >nul 2>&1


ECHO. & ECHO 清理驱动程序....
FOR %%i in ("%Windir%\INF\OEM*.inf") do (
    FIND.exe /i "VMWare, Inc." "%%~i" >nul && (
        Devcon%vmbit%.exe dp_delete %%~nxi
    )
)


ECHO. & ECHO 清理注册表^(残余项^)....
REG.exe delete "HKLM\SOFTWARE\Classes\TypeLib\{16A76DDB-46C2-4AB4-9A74-755B80DDEB4E}" /f >nul 2>&1

REG.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\PnpLockdownFiles\%%SystemRoot%%/system32/DRIVERS/vmnetadapter.sys" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\PnpLockdownFiles\%%SystemRoot%%/system32/DRIVERS/vmnet.sys" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\PnpLockdownFiles\%%SystemRoot%%/System32/drivers/vmci.sys" /f >nul 2>&1
REG.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\PnpLockdownFiles\%%SystemRoot%%/system32/vnetinst.dll" /f >nul 2>&1

REG.exe delete "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\VMware NAT Service" /f >nul 2>&1
REG.exe delete "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\vmauthd" /f >nul 2>&1
REG.exe delete "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\System\VMnetAdapter" /f >nul 2>&1
REG.exe delete "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\System\VMnetBridge" /f >nul 2>&1
REG.exe delete "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\System\VMnetDHCP" /f >nul 2>&1
REG.exe delete "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\System\hcmon" /f >nul 2>&1
REG.exe delete "HKLM\SYSTEM\CurrentControlSet\Services\VMnetuserif" /f >nul 2>&1
REG.exe delete "HKLM\SYSTEM\CurrentControlSet\Services\vmkbd3" /f >nul 2>&1
REG.exe delete "HKLM\SYSTEM\CurrentControlSet\Services\vmx86" /f >nul 2>&1
REG.exe delete "HKLM\SYSTEM\CurrentControlSet\Services\hcmon" /f >nul 2>&1

goto :AllTheEnd
::--------------------------------------------------------------------------------------------------------------------------::



::------------------------------------------------- Windows 版本不完全列表 -------------------------------------------------::
:OSVer
CLS & ECHO.
IF %ARCH% NEQ x64  TITLE 不支持该系统 [%~nx0]
IF %OSBuild% LSS 7601 TITLE 不支持该系统 [%~nx0]
ECHO  系统版本    系统名称                       系统版本    系统名称
ECHO  ----------  ----------------------------   ----------  -----------------------
ECHO  10.0.18362  Windows 10 1903                10.0.15063  Windows 10 1703
ECHO  10.0.17763  Windows 10 1809                10.0.14393  Windows 10 1607
ECHO  10.0.17134  Windows 10 1803                10.0.10586  Windows 10 1511
ECHO  10.0.16299  Windows 10 1709                10.0.10240  Windows 10 1507
ECHO.
ECHO   6.3.9600   Windows 8.1 Update              6.1.7600   Windows 7
ECHO   6.3.9600   Windows 8.1                     6.0.6002   Windows Vista SP2
ECHO   6.2.9200   Windows 8                       6.0.6001   Windows Server 2008
ECHO   6.1.7601   Windows Server 2008 R2          6.0.6001   Windows Vista SP1
ECHO   6.1.7601   Windows 7 SP1                   6.0.6000   Windows Vista
ECHO.
ECHO   5.0.3790   Windows Server 2003/SP1/SP2     4.1.2222   Windows 98 SE
ECHO   5.0.2600   Windows XP/SP1/SP2/SP3          4.1.1998   Windows 98
ECHO   5.0.2195   Windows 2000/SP1/SP2/SP3/SP4    4.0.1214   Windows 97
ECHO   4.9.3000   Windows ME                      4.0.950    Windows 95
ECHO  ----------  ----------------------------   ----------  -----------------------
ECHO  当前版本[%ARCH% @ %NTv%.%OSBuild%], 最低要求[x64 @ 6.1.7601].
ECHO  ------------------------------------------------------------------------------
ECHO. & ECHO  按任意键退出... & PAUSE>nul & Exit
::--------------------------------------------------------------------------------------------------------------------------::


::-------------------------------------------------------- 刷新图标 --------------------------------------------------------::
:iconRefresh
ECHO [Version]>"%Temp%\iconRefresh.inf"
ECHO Signature="$CHICAGO$">>"%Temp%\iconRefresh.inf"
ECHO [DefaultInstall]>>"%Temp%\iconRefresh.inf"
ECHO AddReg=AddReg>>"%Temp%\iconRefresh.inf"
ECHO [AddReg]>>"%Temp%\iconRefresh.inf"
InfDefaultInstall.exe "%Temp%\iconRefresh.inf"
DEL /f /q "%Temp%\iconRefresh.inf"
goto :eof
::--------------------------------------------------------------------------------------------------------------------------::


::------------------------------------------------------ 启用网络服务 ------------------------------------------------------::
:NetWork
REG.exe query "HKLM\SYSTEM\CurrentControlSet\Services\vmnetuserif" >nul 2>nul && (ECHO. & ECHO 无需重复安装，按任意键退出... & PAUSE>nul & Exit)
REG.exe query "HKLM\SYSTEM\CurrentControlSet\Services\vmx86" >nul 2>nul || goto :Begin


ECHO. & ECHO 安装网络VSOCK服务...
IF %OSBuild% GEQ 9200 (SET "NTv=NT10") ELSE (SET "NTv=NT6")
Devcon%vmbit%.exe dp_add "%DataPATH%\Drivers\vsock_%NTv%\vsock.inf"
SC.exe create vsock type= kernel Error= ignore start= boot binpath= "%Windir%system32\drivers\vsock.sys" Group= "System Bus Extender" displayname= "vSockets Virtual Machine Communication Interface Sockets driver"
SC.exe Description "vsock" "vSockets Driver"
SC.exe start vsock>nul

ECHO. & ECHO 安装网络桥接服务^(VMnetBridge^)...
Devcon%vmbit%.exe dp_add "%CD%\netbridge.inf"
Devcon%vmbit%.exe dp_add "%CD%\netuserif.inf"
Devcon%vmbit%.exe dp_add "%CD%\netadapter.inf"
START /wait vnetlib%vmbit%.exe -- install adapter
START /wait vnetlib%vmbit%.exe -- install userif
START /wait vnetlib%vmbit%.exe -- install bridge
START /wait vnetlib%vmbit%.exe -- start bridge

ECHO. & ECHO 安装网络DHCP服务^(VMnetDHCP^)...
START /wait vnetlib.exe -- install dhcp
START /wait vnetlib.exe -- start dhcp
SC.exe start Dhcp>nul

ECHO. & ECHO 安装虚拟网卡1^(用于 Host-only^)...
START /wait vnetlib.exe -- add adapter vmnet1
START /wait vnetlib.exe -- add dhcp vmnet1
START /wait vnetlib.exe -- set vnet vmnet1 addr 10.10.10.0
START /wait vnetlib.exe -- stop dhcp
START /wait vnetlib.exe -- update dhcp vmnet1
START /wait vnetlib.exe -- start dhcp
START /wait vnetlib.exe -- update adapter vmnet1

ECHO. & ECHO 安装网络NAT服务^(VMware NAT Service^)...
START /wait vnetlib.exe -- install nat

ECHO. & ECHO 安装虚拟网卡8^(用于 VMware NAT^)...
START /wait vnetlib.exe -- add adapter vmnet8
START /wait vnetlib.exe -- add dhcp vmnet8
START /wait vnetlib.exe -- add nat vmnet8
START /wait vnetlib.exe -- set vnet vmnet8 addr 192.168.128.0
START /wait vnetlib.exe -- stop nat
START /wait vnetlib.exe -- stop dhcp
START /wait vnetlib.exe -- update dhcp vmnet8
START /wait vnetlib.exe -- start dhcp
START /wait vnetlib.exe -- update nat vmnet8
START /wait vnetlib.exe -- start nat
START /wait vnetlib.exe -- update adapter vmnet8

IF /i "%1" EQU "NetWork" goto :AllTheEnd
goto :eof
::--------------------------------------------------------------------------------------------------------------------------::



:VirtualPrinter
ECHO. & ECHO 安装虚拟打印机服务...
REG.exe add "HKLM\SOFTWARE\Wow6432Node\ThinPrint" /v Lang /t REG_SZ /d "enu" /f
REG.exe add "HKLM\SOFTWARE\Wow6432Node\ThinPrint\Client" /v DefPrintState /t REG_DWORD /d "0x00000001" /f
REG.exe add "HKLM\SOFTWARE\Wow6432Node\ThinPrint\Client" /v DefaultState /t REG_DWORD /d "0x00000001" /f
REG.exe add "HKLM\SOFTWARE\Wow6432Node\ThinPrint\Client" /v PropertyRequestTimeout /t REG_DWORD /d "0x00000078" /f
REG.exe add "HKLM\SOFTWARE\Wow6432Node\ThinPrint\Client" /v WatchPrinters /t REG_DWORD /d "0x00000001" /f
7za.exe x -y "%DataPATH%\CF32_ThinPrint.7z" -o"%CommonProgramFiles(x86)%"
START /wait vnetlib%vmbit%.exe -- install parport
START /wait vnetlib%vmbit%.exe -- start parport
goto :eof


:Hostd
ECHO. & ECHO 安装共享虚拟机和远程访问服务^(Hostd^)...
SC.exe start LanmanWorkstation>nul
SC.exe start VMAuthdService>nul
SC.exe start VMUSBArbService>nul
7za.exe x -y "%DataPATH%\Data_AllUsers_HostID.7z" -o"%AllUsersProfile%"
IF NOT EXIST "%AllUsersProfile%\VMware\SSL\rui.key" openssl.exe req -x509 -days 365 -newkey rsa:2048 -keyout "%AllUsersProfile%\VMware\SSL\rui.key" -out "%AllUsersProfile%\VMware\SSL\rui.crt" -config "%AllUsersProfile%\VMware\SSL\hostd.ssl.config"
STR.exe "%AllUsersProfile%\VMware\hostd\config.xml" 0 0 /R /asc:"C:\Program Files (x86)\VMware\VMware Workstation" /asc:"%CD%" /A >nul 2>nul
STR.exe "%AllUsersProfile%\VMware\hostd\config.xml" 0 0 /R /asc:"C:\ProgramData\VMware" /asc:"%AllUsersProfile%\VMware" /A >nul 2>nul
STR.exe "%AllUsersProfile%\VMware\hostd\datastores.xml" 0 0 /R /asc:"VMwareDir" /asc:"%CD%" /A >nul 2>nul

SC.exe create VMwareHostd start= auto depend= VMAuthdService/VMUSBArbService/lanmanworkstation binpath= "%CD%\vmware-hostd.exe -u \"%AllUsersProfile%\VMware\hostd\config.xml\"" displayname= "VMware Workstation Server"
SC.exe Description "VMwareHostd" "Remote access service for registration and management of virtual machines."
REG.exe add "HKLM\SYSTEM\CurrentControlSet\services\VMwareHostd" /v FailureCommand /t REG_SZ /d "\"%CD%\vm-support.vbs\"" /f
SC.exe start VMwareHostd>nul
goto :eof
