cls
@ECHO OFF
CLS
color 0a
Title 安装 VMware Workstation 服务
set vmbit=
IF "%PROCESSOR_ARCHITECTURE%" neq "x86" set vmbit=64

:menu
cls
echo.
echo               精简版相关服务安装 主菜单
echo              ===========================
echo.
echo               0、一键安装所有服务(USB、VMwareHost和打印机服务请另外安装)
echo               1、网络功能
echo               2、USB设备支持服务
echo               3、磁盘映射功能
echo               4、授权服务(Unity宿主化与后台运行必装)
echo               5、视频播放解码
echo               6、虚拟打印机服务
echo               7、安装WEB访问服务(VMwareHost服务)
echo               8、安装增强虚拟键盘驱动
echo               9、清理不必要的文件(节省硬盘空间)
echo               e、退   出
echo.
echo               提示：0-7项不安装或全部禁用即为最小模式
:cl
echo.
set /p choice=              请选择要进行的操作，然后按回车: 
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="0" goto s0
if /i "%choice%"=="1" goto s1
if /i "%choice%"=="2" goto s2
if /i "%choice%"=="3" goto s3
if /i "%choice%"=="4" goto s4
if /i "%choice%"=="5" goto s5
if /i "%choice%"=="6" goto s6
if /i "%choice%"=="7" goto s7
if /i "%choice%"=="8" goto s8
if /i "%choice%"=="9" goto clean
if /i "%choice%"=="e" goto EX

echo.
echo              选择无效，请重新输入
echo.
goto cl

:s0
:s0cl
echo.
set /p no=          请再次确认是否安装全部服务 Y(开始安装)或 N(退出安装)：
echo.
if /I "%no%"=="y" goto ks
if /I "%no%"=="n" exit
echo           输入错误，请重新输入...
goto s0cl
:ks
echo 	       正在安装，请稍后...
cd /d "%~dp0"
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMnetBridge >nul 2>nul&&(echo.&echo 请先卸载干净再安装!!!&pause>nul&goto MENU)
reg query HKLM\SYSTEM\CurrentControlSet\Services\vmnetuserif >nul 2>nul || (vnetlib%vmbit%.exe -- install userif)
start /wait vnetlib%vmbit%.exe -- start userif >nul 2>nul
rundll32 setupapi,InstallHinfSection _Install1.NT 128 .\netadapter.inf >nul
start /wait vnetlib%vmbit%.exe -- install bridge
start /wait vnetlib%vmbit%.exe -- start bridge

start /wait vnetlib.exe -- install dhcp
start /wait vnetlib.exe -- start dhcp

net start Dhcp >nul 2>nul

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

start /wait vnetlib.exe -- install 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

start /wait vnetlib.exe -- install authd
start /wait vnetlib.exe -- start authd
net start VMAuthdService >nul 2>nul

IF "%PROCESSOR_ARCHITECTURE%" neq "x86" goto 64d else goto 86d
:86d
copy /y vmnc.dll %windir%\system32 >nul 2>nul
copy /y 86Drv\vstor2-mntapi10-shared.sys %windir%\system32\drivers >nul 2>nul
sc create vstor2-mntapi10-shared type= kernel start= auto binpath= "%WinDir%\System32\drivers\vstor2-mntapi10-shared.sys" displayname= "Vstor2 MntApi 1.0 Driver (shared)"
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Drivers32" /f /v "VIDC.VMnc" /t REG_SZ /d "vmnc.dll" >nul 2>nul
goto nextins
:64d
copy /y 64Drv\SysWOW64\Drivers\vstor2-mntapi10-shared.sys %windir%\SysWOW64\drivers >nul 2>nul
copy /y vmnc.dll %windir%\SysWOW64 >nul 2>nul
sc create vstor2-mntapi10-shared type= kernel start= auto binpath= "%WinDir%\SysWOW64\drivers\vstor2-mntapi10-shared.sys" displayname= "Vstor2 MntApi 1.0 Driver (shared)"
reg add "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Drivers32" /f /v "VIDC.VMnc" /t REG_SZ /d "vmnc.dll" >nul 2>nul
:nextins
net start vstor2-mntapi10-shared >nul

echo.
echo              一键安装所有服务成功！任意键返回主菜单
echo              你也可在后面的菜单中禁用不需要的服务
pause >nul
goto menu

:s1
cls
echo                     网络服务菜单
echo              ==========================
echo.
echo               1、bridge(桥接)
echo.
echo               2、nat(网络共享)
echo.
echo               3、host-only(仅为主机)
echo.
echo               4、禁用VMnetDHCP服务
echo.
echo               5、启用VMnetDHCP服务
echo.
echo               6. 禁用全部网络功能
echo.
echo               7、返回主菜单
echo.
echo               温馨提示:
echo                   如果只安装第一项或安装第二、第三项时想手
echo               动设置虚拟机IP/网关/DNS才可禁用VMnetDHCP服务；
echo               请不要在未重启系统时反复启用或停用某种网络服务；
:cl1
echo.
set /p choice=          请选择: 
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="1" goto n1
if /i "%choice%"=="2" goto n2
if /i "%choice%"=="3" goto n3
if /i "%choice%"=="4" goto n4
if /i "%choice%"=="5" goto n5
if /i "%choice%"=="6" goto n6
if /i "%choice%"=="7" goto menu
echo.
echo              选择无效，请重新输入
echo.
goto cl1

:n1
cls
echo.
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo             请选择要进行的操作，然后按回车
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo               1、禁用桥接服务
echo.
echo               2、启用桥接服务
echo.
echo               3、返回网络服务菜单
echo.
:cl11
echo.
set /p choice=          请选择: 
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="1" goto n11
if /i "%choice%"=="2" goto n12
if /i "%choice%"=="3" goto s1
echo.
echo              选择无效，请重新输入
echo.
goto cl11

:n11
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMnetBridge >nul 2>nul||(echo.&echo 桥接服务已经禁用!任意键返回网络服务菜单&pause>nul&goto s1)
vnetlib%vmbit%.exe -- stop bridge
vnetlib%vmbit%.exe -- uninstall bridge
echo.
echo              禁用桥接服务成功!重启后生效!任意键返回网络服务菜单
echo.
pause >nul
goto s1

:n12
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMnetBridge >nul 2>nul&&(echo.&net start VMnetBridge >nul &&echo 桥接服务已经启用!任意键返回网络服务菜单&pause>nul&goto s1)
reg query HKLM\SYSTEM\CurrentControlSet\Services\vmnetuserif >nul 2>nul || (vnetlib%vmbit%.exe -- install userif)
start /wait vnetlib%vmbit%.exe -- start userif >nul 2>nul
rundll32 setupapi,InstallHinfSection _Install1.NT 128 .\netadapter.inf >nul
start /wait vnetlib%vmbit%.exe -- install bridge
start /wait vnetlib%vmbit%.exe -- start bridge
echo.
echo              启用桥接服务成功!任意键返回网络服务菜单
echo.
pause >nul
goto s1

:n2
cls
echo.
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo             请选择要进行的操作，然后按回车
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo               1、禁用nat服务
echo.
echo               2、启用nat服务（默认安装虚拟网卡8）
echo.
echo               3、返回网络服务菜单
echo.
:cl12
echo.
set /p choice=          请选择: 
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="1" goto n21
if /i "%choice%"=="2" goto n22
if /i "%choice%"=="3" goto s1
echo.
echo              选择无效，请重新输入
echo.
goto cl12

:n21
reg query "HKLM\SYSTEM\CurrentControlSet\Services\VMware NAT Service" >nul 2>nul||(echo.&echo nat服务已经禁用!任意键返回网络服务菜单&pause>nul&goto s1)
vnetlib.exe -- remove adapter vmnet8
vnetlib.exe -- stop nat & vnetlib.exe -- uninstall nat
echo.
echo              禁用nat服务成功!重启后生效!任意键返回网络服务菜单
echo.
pause >nul
goto s1

:n22
reg query "HKLM\SYSTEM\CurrentControlSet\Services\VMware NAT Service" >nul 2>nul&&(echo.&net start "VMware NAT Service" >nul &&echo nat服务已经启用!任意键返回网络服务菜单&pause>nul&goto s1)
net start Dhcp >nul 2>nul
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMnetuserif >nul 2>nul || (vnetlib%vmbit%.exe -- install userif)
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMnetDHCP >nul 2>nul || (vnetlib.exe -- install dhcp)
vnetlib.exe -- install nat
vnetlib.exe -- add adapter vmnet8
vnetlib.exe -- add dhcp vmnet8
vnetlib.exe -- add nat vmnet8
vnetlib.exe -- set vnet vmnet8 addr 192.168.128.0
vnetlib.exe -- stop nat
vnetlib.exe -- stop dhcp
vnetlib.exe -- update dhcp vmnet8
vnetlib.exe -- start dhcp
vnetlib.exe -- update nat vmnet8
vnetlib.exe -- start nat
vnetlib.exe -- update adapter vmnet8
echo.
echo              启用nat服务成功!重启后生效!任意键返回网络服务菜单
echo.
pause >nul
goto s1

:n3
cls
echo.
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo             请选择要进行的操作，然后按回车
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo               1、禁用host-only服务
echo.
echo               2、启用host-only服务（默认安装虚拟网卡1）
echo.
echo               3、返回网络服务菜单
echo.
echo.
:cl13
echo.
set /p choice=          请选择: 
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="1" goto n31
if /i "%choice%"=="2" goto n32
if /i "%choice%"=="3" goto s1
echo.
echo              选择无效，请重新输入
echo.
goto cl13

:n31
vnetlib%vmbit%.exe -- remove adapter vmnet1
echo.
echo              禁用host-only服务成功!重启后生效!任意键返回网络服务菜单
echo.
pause >nul
goto s1

:n32
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMnetuserif >nul 2>nul||(vnetlib%vmbit%.exe -- install userif)
net start Dhcp >nul 2>nul
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMnetDHCP >nul 2>nul||(vnetlib.exe -- install dhcp)
vnetlib.exe -- add adapter vmnet1
vnetlib.exe -- add dhcp vmnet1
vnetlib.exe -- set vnet vmnet1 addr 10.10.10.0
vnetlib.exe -- stop dhcp
vnetlib.exe -- update dhcp vmnet1
vnetlib.exe -- start dhcp
vnetlib.exe -- update adapter vmnet1
echo.
echo              启用host-only服务成功!任意键返回网络服务菜单
echo.
pause >nul
goto s1

:n4
reg query HKLM\SYSTEM\CurrentControlSet\Services\vmnetdhcp >nul 2>nul&&(vnetlib.exe -- stop dhcp & vnetlib.exe -- uninstall dhcp)
echo.
echo              禁用VMnetDHCP服务成功!重启后生效!任意键返回网络服务菜单
echo.
pause >nul
goto s1

:n5
reg query HKLM\SYSTEM\CurrentControlSet\Services\vmnetdhcp >nul 2>nul||(vnetlib.exe -- install dhcp & vnetlib.exe -- start dhcp)
echo.
echo              启用VMnetDHCP服务成功!任意键返回网络服务菜单
echo.
pause >nul
goto s1

:n6
vnetlib%vmbit%.exe -- uninstall adapter
echo.
echo              禁用全部网络服务成功!重启后生效!任意键返回网络服务菜单
echo.
pause >nul
goto s1

:s2
cls
echo.
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo             请选择要进行的操作，然后按回车
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo               1、禁用USB服务
echo.
echo               2、启动USB服务
echo.
echo               3、返回主菜单
echo.
echo               4、退出
:cl2
echo.
set /p choice=          请选择: 
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="1" goto s21
if /i "%choice%"=="2" goto s22
if /i "%choice%"=="3" goto menu
if /i "%choice%"=="4" exit
echo.
echo              选择无效，请重新输入
echo.
goto cl2
:s21
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMUSBArbService >nul 2>nul||(echo.&echo USB服务已经禁用!任意键返回主菜单&pause>nul&goto menu)
net stop VMUSBArbService >nul 2>nul
sc delete VMUSBArbService >nul 2>nul
vnetlib%vmbit%.exe -- stop usb
vnetlib%vmbit%.exe -- uninstall usb
vnetlib%vmbit%.exe -- stop hcmon
vnetlib%vmbit%.exe -- uninstall hcmon
rmdir /s /q "%CommonProgramFiles%\VMware\USB" >nul 2>nul
IF "%PROCESSOR_ARCHITECTURE%" neq "x86" rmdir /s /q "%CommonProgramFiles(x86)%\VMware" >nul 2>nul
echo.
echo              禁用USB服务成功!重启后生效!任意键返回主菜单
echo.
pause >nul
goto menu

:s22
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMUSBArbService >nul 2>nul&&(echo.&net start VMUSBArbService >nul&&echo USB服务已经启动!任意键返回主菜单&pause>nul&goto menu)
IF "%PROCESSOR_ARCHITECTURE%" equ "x86" (xcopy USB\x86\* USB\ /E /Y >nul) 
IF "%PROCESSOR_ARCHITECTURE%" neq "x86" (
copy /y USB\x64\hcmon.sys1 USB\hcmon.sys >nul
copy /y USB\x64\vmusb.cat1 USB\vmusb.cat >nul
copy /y USB\x64\vmusb.sys1 USB\vmusb.sys >nul
)
IF "%PROCESSOR_ARCHITECTURE%" neq "x86" set CommonPath=%CommonProgramFiles(x86)%\VMware\USB
IF "%PROCESSOR_ARCHITECTURE%" equ "x86" set CommonPath=%CommonProgramFiles%\VMware\USB
mkdir "%CommonPath%"
xcopy .\USB\* "%CommonPath%\" /E /Y >nul
cd /d "%CommonPath%"
vnetlib%vmbit%.exe -- install hcmon
if not exist %WinDir%\system32\drivers\hcmon.sys copy /y "%CommonPath%\hcmon.sys" %WinDir%\system32\drivers\
vnetlib%vmbit%.exe -- start hcmon
ver|find "6.">nul && goto s222
ver|find "5.">nul && goto s221
:s221
rundll32 setupapi,InstallHinfSection _Install1.NT 128 %CommonPath%\vmusb.inf
goto s223
:s222
pnputil.exe -i -a "%CommonPath%\vmusb.inf" >nul 2>nul
:s223
sc create VMUSBArbService binpath= "\"%CommonPath%\vmware-usbarbitrator%vmbit%.exe\"" start= auto displayname= "VMware USB Arbitration Service" >nul
cd /d "%~dp0"
net start VMUSBArbService
echo.
echo              启动USB服务成功!任意键返回主菜单
echo.
pause >nul
goto menu

:s3
cls
echo.
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo             请选择要进行的操作，然后按回车
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo               1、禁用“磁盘映射功能”
echo.
echo               2、启用“磁盘映射功能”
echo.
echo               3、返回主菜单
echo.
echo               4、退出
:cl3
echo.
set /p choice=          请选择: 
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="1" goto s31
if /i "%choice%"=="2" goto s32
if /i "%choice%"=="3" goto menu
if /i "%choice%"=="4" exit
echo.
echo              选择无效，请重新输入
echo.
goto cl3

:s31
reg query "HKLM\SYSTEM\CurrentControlSet\Services\vstor2-mntapi10-shared" >nul 2>nul||(echo.&echo 磁盘映射功能已经禁用!任意键返回主菜单&pause>nul&goto menu)
net stop vstor2-mntapi10-shared >nul
sc delete vstor2-mntapi10-shared >nul
echo.
echo              禁用磁盘映射功能成功!任意键返回本级菜单
echo.
pause >nul
goto s3

:s32
reg query "HKLM\SYSTEM\CurrentControlSet\Services\vstor2-mntapi10-shared" >nul 2>nul&&(echo.&net start "vstor2-mntapi10-shared" >nul &&echo 磁盘映射功能已经启用!任意键返回主菜单&pause>nul&goto menu)
if "%PROCESSOR_ARCHITECTURE%" neq "x86" goto s322
:s321
copy /y 86Drv\vstor2-mntapi10-shared.sys %systemroot%\system32\drivers\ >nul
sc create vstor2-mntapi10-shared type= kernel start= auto binpath= "%WinDir%\System32\drivers\vstor2-mntapi10-shared.sys" displayname= "Vstor2 MntApi 1.0 Driver (shared)"
net start vstor2-mntapi10-shared >nul
goto :s323
:s322
if not exist %WinDir%\SysWOW64\drivers\vstor2-mntapi10-shared.sys copy /y 64Drv\SysWOW64\Drivers\vstor2-mntapi10-shared.sys
sc create vstor2-mntapi10-shared type= kernel start= auto binpath= "%WinDir%\SysWOW64\drivers\vstor2-mntapi10-shared.sys" displayname= "Vstor2 MntApi 1.0 Driver (shared)"
net start vstor2-mntapi10-shared >nul
:s323
echo.
echo              启用磁盘映射功能成功!任意键返回本级菜单
echo.
pause >nul
goto s3

:s4
cls
echo.
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo             请选择要进行的操作，然后按回车
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo               1、禁用授权服务
echo.
echo               2、启用授权服务
echo.
echo               3、返回主菜单
echo.
echo               4、退出
:cl4
echo.
set /p choice=          请选择: 
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="1" goto s41
if /i "%choice%"=="2" goto s42
if /i "%choice%"=="3" goto menu
if /i "%choice%"=="4" exit
echo.
echo              选择无效，请重新输入
echo.
goto cl4

:s41
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMAuthdService >nul 2>nul||(echo.&echo 授权服务已经禁用!任意键返回主菜单&pause>nul&goto menu)
start /wait vnetlib.exe -- stop authd
start /wait vnetlib.exe -- unstalll authd
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMAuthdService >nul 2>nul&&(net stop VMAuthdService >nul 2>nul&&sc delete VMAuthdService >nul 2>nul)
echo.
echo              禁用授权服务成功!重启后生效!任意键返回主菜单
echo.
pause >nul
goto menu

:s42
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMAuthdService >nul 2>nul&&(echo.&net start VMAuthdService >nul &&echo 授权服务已经启用!任意键返回主菜单&pause>nul&goto menu)
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)
echo.
echo              启用授权服务成功!任意键返回主菜单
echo.
pause >nul
goto menu

:s5
if "%PROCESSOR_ARCHITECTURE%" neq "x86" goto s52
:s51
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Drivers32" /f /v "VIDC.VMnc" /t REG_SZ /d "vmnc.dll" >nul
copy /y vmnc.dll %windir%\system32\ >nul 2>nul
goto s53
:s52
copy /y vmnc.dll %windir%\SysWOW64\ >nul 2>nul
reg add "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Drivers32" /f /v "VIDC.VMnc" /t REG_SZ /d "vmnc.dll" >nul
:s53
echo.
echo              视频播放解码支持安装成功!任意键返回主菜单
echo.
pause >nul
goto menu

:s6
cls
echo.
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo             请选择要进行的操作，然后按回车
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo               1、禁用虚拟打印机服务
echo.
echo               2、启用虚拟打印机服务
echo.
echo               3、返回主菜单
echo.
echo               4、退出
:cl6
echo.
set /p choice=          请选择: 
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="1" goto s61
if /i "%choice%"=="2" goto s62
if /i "%choice%"=="3" goto menu
if /i "%choice%"=="4" exit
echo.
echo              选择无效，请重新输入
echo.
goto cl6
:s61
echo              正在禁用虚拟打印机服务...
echo.
start /wait vnetlib%vmbit%.exe -- stop parport
start /wait vnetlib%vmbit%.exe -- uninstall parport
echo.
echo              禁用虚拟打印机服务成功!任意键返回本级菜单
echo.
pause >nul
goto s6
:s62
echo.
echo              正在安装虚拟打印机服务...
echo.
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMparport >nul 2>nul && (echo.&net start VMparport >nul &&echo 打印机串口驱动已经启用!&pause>nul&goto MENU)
start /wait vnetlib%vmbit%.exe -- install parport
start /wait vnetlib%vmbit%.exe -- start parport
echo.
echo              打印机支持安装成功!任意键返回本级菜单
echo.
pause >nul
goto s6

:s7
cls
echo.
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo             请选择要进行的操作，然后按回车
echo             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo. 提示:安装此服务可以通过客户端远程连接到服务器端
echo.      进行远程创建和管理服务器上的虚拟机等操作,以及
echo.      查看远程服务器的CPU、内存、硬盘资源的状态等.
echo.
echo.
echo               1、禁用WEB访问服务
echo.
echo               2、启用WEB访问服务
echo.
echo               3、返回主菜单
echo.
echo               4、退出
:cl7
echo.
set /p choice=          请选择: 
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="1" goto s71
if /i "%choice%"=="2" goto s72
if /i "%choice%"=="3" goto menu
if /i "%choice%"=="4" exit
echo.
echo              选择无效，请重新输入
echo.
goto cl7
:s71
echo              正在禁用WEB访问服务
echo.
net stop VMwareHostd
sc delete VMwareHostd >nul 2>nul
rd /s /q "%AllUsersProfile%\Application Data\VMware\hostd" >nul 2>nul
rd /s /q "%AllUsersProfile%\Application Data\VMware\SSL" >nul 2>nul
ver|find "6.">nul && (set profilepath=%AllUsersProfile%)
ver|find "5.">nul && (set profilepath=%AllUsersProfile%\Application Data)
start /wait str.exe "%profilepath%\VMware\hostd\config.xml" 0 0 /R /asc:"%cd%" /asc:"VMwareDir" /A >nul 2>nul
start /wait str.exe "%profilepath%\VMware\hostd\datastores.xml" 0 0 /R /asc:"%cd%" /asc:"VMwareDir" /A >nul 2>nul
start /wait str.exe "%profilepath%\VMware\hostd\stats\hostAgentStats.xml" 0 0 /R /asc:"%profilepath%\VMware" /asc:"hostdDir" /A >nul 2>nul
start /wait str.exe "%profilepath%\VMware\hostd\config.xml" 0 0 /R /asc:"%profilepath%\VMware" /asc:"hostdDir" /A >nul 2>nul
echo.
cls
echo              禁用WEB访问服务!任意键返回主菜单
echo.
pause >nul
goto menu
:s72
echo.
echo              正在启用WEB访问服务
echo.

reg query HKLM\SYSTEM\CurrentControlSet\Services\VMUSBArbService >nul 2>nul || (echo.&echo 请先安装USB服务!任意键返回主菜单&pause>nul&goto menu)
reg query HKLM\SYSTEM\CurrentControlSet\Services\VMwareHostd >nul 2>nul && (echo.&net start VMwareHostd >nul &&echo WEB访问服务已经启用!&pause>nul&goto MENU)
net start LanmanWorkstation >nul 2>nul
net start VMAuthdService >nul 2>nul
net start VMUSBArbService >nul 2>nul
ver|find "6.">nul && (set profilepath=%AllUsersProfile%)
ver|find "5.">nul && (set profilepath=%AllUsersProfile%\Application Data)
md "%profilepath%\VMware\hostd" >nul 2>nul
md "%profilepath%\VMware\SSL" >nul 2>nul
xcopy Web\* "%profilepath%\VMware\hostd" /E /Y >nul 2>nul
copy /y SSL\hostd.ssl.config "%profilepath%\VMware\SSL\" >nul 2>nul
if not exist "%profilepath%\VMware\SSL\rui.key" openssl.exe req -x509 -days 365 -newkey rsa:2048 -keyout "%profilepath%\VMware\SSL\rui.key" -out "%profilepath%\VMware\SSL\rui.crt" -config "%profilepath%\VMware\SSL\hostd.ssl.config"

start /wait str.exe "%profilepath%\VMware\hostd\config.xml" 0 0 /R /asc:"VMwareDir" /asc:"%cd%" /A >nul 2>nul
start /wait str.exe "%profilepath%\VMware\hostd\datastores.xml" 0 0 /R /asc:"VMwareDir" /asc:"%cd%" /A >nul 2>nul
start /wait str.exe "%profilepath%\VMware\hostd\stats\hostAgentStats.xml" 0 0 /R /asc:"hostdDir" /asc:"%profilepath%\VMware" /A >nul 2>nul
start /wait str.exe "%profilepath%\VMware\hostd\config.xml" 0 0 /R /asc:"hostdDir" /asc:"%profilepath%\VMware" /A >nul 2>nul

sc create VMwareHostd binpath= "%cd%\vmware-hostd.exe -u \"%profilepath%\VMware\hostd\config.xml\"" start= auto depend= VMAuthdService/VMUSBArbService/lanmanworkstation  displayname= "VMware Workstation Server"

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\VMwareHostd" /v FailureCommand /t REG_SZ /d "\"%cd%\vm-support.vbs\"" /f

net start VMwareHostd
echo.
echo              WEB访问服务安装成功!任意键返回主菜单
echo.
pause >nul
goto menu

:s8
echo.
echo              正在启用增强虚拟键盘服务
echo.
IF "%PROCESSOR_ARCHITECTURE%" equ "x86" copy /y 86Drv\VMkbd.sys %WinDir%\system32\drivers\ >nul 2>nul
IF "%PROCESSOR_ARCHITECTURE%" neq "x86" copy /y 64Drv\VMkbd.sys %WinDir%\system32\drivers\ >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\Installer\VMware Workstation\Features" /v vmkbd /t REG_SZ /d "%WinDir%\\BadPath" /f
sc create vmkbd binpath= "%windir%\system32\drivers\VMkbd.sys" Type= kernel  start= demand Group= "Keyboard Port" error= normal displayname= "VMware kbd"
echo.
echo              增强虚拟键盘驱动安装成功!任意键返回主菜单
echo.
pause >nul
goto menu

:clean
echo.
echo              正在清理不必要的文件...
echo.
rd /s /q 86Drv >nul 2>nul
rd /s /q 64Drv >nul 2>nul
echo.
cls
echo              文件清理完成
echo.
GOTO MENU

:EX
exit