cls
@echo off
CLS
color 0a
Title 卸载 VMware
set vmbit=
if "%PROCESSOR_ARCHITECTURE%" neq "x86" set vmbit=64

echo 你确定要卸载 VMware 或者清理VMware残留信息吗?
echo 按任意键继续卸载 VMware,否则请关闭窗口 !!!&pause>nul

echo 正在删除服务和设备,可能需要几分钟,请稍后...
echo 如果三分钟后还没动静,请在卸载批处理命令窗口上敲一下回车键后继续等待...

cd /d "%~dp0"
vnetlib%vmbit%.exe -- stop authd >nul 2>nul
vnetlib%vmbit%.exe -- uninstall authd >nul 2>nul
net stop VMAuthdService >nul 2>nul
sc delete VMAuthdService >nul 2>nul
net stop VMwareHostd >nul 2>nul
sc delete VMwareHostd >nul 2>nul

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

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 >nul 2>nul
vnetlib%vmbit%.exe -- uninstall hcmon >nul 2>nul

net stop vstor2-mntapi20-shared >nul 2>nul
sc delete vstor2-mntapi20-shared >nul 2>nul

vnetlib%vmbit%.exe -- stop vmkbd >nul 2>nul
vnetlib%vmbit%.exe -- uninstall vmkbd >nul 2>nul
net stop vmkbd >nul 2>nul
sc delete vmkbd >nul 2>nul

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

ver|find "5.">nul && (DrvInst.exe -uninstall "ROOT\VMWVMCIHOSTDEV" 0 >nul 2>nul)
ver|find "5.">nul || (devcon%vmbit%.exe remove "ROOT\VMWVMCIHOSTDEV" >nul 2>nul)

vnetlib%vmbit%.exe -- stop vsock >nul 2>nul
net stop vsock >nul 2>nul
sc delete vsock >nul 2>nul

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

vnetlib%vmbit%.exe -- uninstall vmci
echo.

echo 取消DLL文件的注册...
regsvr32 /u /s "%cd%\vmappcfg.dll"
regsvr32 /u /s "%cd%\vmappsdk.dll"
regsvr32 /u /s "%cd%\vmdbCOM.dll"
regsvr32 /u /s "%cd%\elevated.dll"
regsvr32 /u /s "%cd%\x64\vmdkShellExt64.dll" >nul 2>nul
regsvr32 /u /s "%cd%\vmdkShellExt.dll"
echo.

echo 删除注册表....
reg delete "HKEY_CURRENT_USER\SOFTWARE\ThinPrint" /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\ThinPrint" /f >nul 2>nul
reg delete "HKEY_CURRENT_USER\SOFTWARE\VMware, Inc." /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc." /f >nul 2>nul
reg delete "HKEY_CURRENT_USER\Software\Wow6432Node\VMware, Inc." /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\Software\Wow6432Node\VMware, Inc." /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Drivers32" /f /v "VIDC.VMnc" >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VMware" /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmware.exe" /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmplayer.exe" /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\A57F49D06AE015943BFA1B54AFE9506C" /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\7A26F0EA2A1AF704F9C48439B99DDAD8" /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\7A79579133DA8984D9E8376086814B46" /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\A116201D664610145AD115603930CA56" /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\BC78C1BA70810FC44B2CEC1EC481DC4B" /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\C3839DFF5D1079849A4534FA95A9DE03" /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\DBBFB30076C6E9142AD4D0ACCFA32594" /f >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /f /v "vmware-tray" >nul 2>nul
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run" /f /v "vmware-tray" >nul 2>nul
reg delete "HKEY_CLASSES_ROOT\Installer\Products\7A26F0EA2A1AF704F9C48439B99DDAD8" /f >nul 2>nul
reg delete "HKEY_CLASSES_ROOT\Installer\Products\7A79579133DA8984D9E8376086814B46" /f >nul 2>nul
reg delete "HKEY_CLASSES_ROOT\Installer\Products\A116201D664610145AD115603930CA56" /f >nul 2>nul
reg delete "HKEY_CLASSES_ROOT\Installer\Products\A57F49D06AE015943BFA1B54AFE9506C" /f >nul 2>nul
reg delete "HKEY_CLASSES_ROOT\Installer\Products\BC78C1BA70810FC44B2CEC1EC481DC4B" /f >nul 2>nul
reg delete "HKEY_CLASSES_ROOT\Installer\Products\C3839DFF5D1079849A4534FA95A9DE03" /f >nul 2>nul
reg delete "HKEY_CLASSES_ROOT\Installer\Products\DBBFB30076C6E9142AD4D0ACCFA32594" /f >nul 2>nul
echo.

:delcl
echo.
set /p ch=         是否删除配置文件 y(删除)或 n(不删除)：
echo.
if /I "%ch%"=="y" goto delset
if /I "%ch%"=="n" goto delfile
echo         输入错误，请重新输入...
goto delcl

:delset
rmdir /s /q "%AllUsersProfile%\Application Data\VMware" >nul 2>nul
rmdir /s /q "%AppData%\VMware" >nul 2>nul

:delfile
echo 删除文件...
rmdir /s /q "%CommonProgramFiles%\VMware" >nul 2>nul
IF "%PROCESSOR_ARCHITECTURE%" neq "x86" rmdir /s /q "%CommonProgramFiles(x86)%\VMware" >nul 2>nul
del /f /q "%WinDir%\system32\vmnc.dll" >nul 2>nul
del /f /q "%WinDir%\SysWOW64\vmnc.dll" >nul 2>nul
del /f /q "%WinDir%\system32\vnetinst.dll" >nul 2>nul
del /f /q "%WinDir%\system32\vnetlib*.dll" >nul 2>nul
del /f /q "%windir%\system32\drivers\vstor2-mntapi20-shared.sys" >nul 2>nul
del /f /q "%WinDir%\SysWOW64\drivers\vstor2-mntapi20-shared.sys" >nul 2>nul
del /f /q "%AllUsersProfile%\桌面\VMware.lnk" >nul 2>nul
del /f /q "%AllUsersProfile%\Desktop\VMware.lnk" >nul 2>nul
del /f /q "%USERPROFILE%\桌面\VMware.lnk" >nul 2>nul
del /f /q "%USERPROFILE%\Desktop\VMware.lnk" >nul 2>nul
del /f /q "%PUBLIC%\Desktop\VMware.lnk" >nul 2>nul
del /f /q "%WinDir%\system32\drivers\vmnet*.sys" >nul 2>nul
del /f /q "%WinDir%\system32\drivers\vmparport.sys" >nul 2>nul
del /f /q "%WinDir%\system32\drivers\VMkbd.sys" >nul 2>nul
del /f /q "%WinDir%\system32\drivers\vmx86.sys" >nul 2>nul
del /f /q "%WinDir%\system32\drivers\vmusb.sys" >nul 2>nul
del /f /q "%WinDir%\system32\drivers\vmci.sys" >nul 2>nul
del /f /q "%WinDir%\system32\vmnetdhcp.exe" >nul 2>nul
del /f /q "%WinDir%\system32\vmnat.exe" >nul 2>nul
del /f /q "%WinDir%\system32\vmnetbridge.dll" >nul 2>nul
del /f /q "%WinDir%\SysWOW64\vmnetdhcp.exe" >nul 2>nul
del /f /q "%WinDir%\SysWOW64\vmnat.exe" >nul 2>nul
echo.

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.

echo 恢复默认安装配置文件...
ver|find "5.">nul || (set profilepath=%AllUsersProfile%)
ver|find "5.">nul && (set profilepath=%AllUsersProfile%\Application Data)
start /wait str.exe preferences.ini 0 0 /R /asc:"%cd%" /asc:"VMwareDir" /A >nul 2>nul
start /wait str.exe environments.xml 0 0 /R /asc:"%cd%" /asc:"VMwareDir" /A >nul 2>nul

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

net stop "VMware NAT Service" >nul 2>nul&&sc delete "VMware NAT Service" >nul 2>nul
net stop VMnetDHCP >nul 2>nul&&sc delete VMnetDHCP >nul 2>nul
net stop VMnetAdapter >nul 2>nul&&sc delete VMnetAdapter >nul 2>nul
net stop vmusb >nul 2>nul&&sc delete vmusb >nul 2>nul
net stop VMnetBridge >nul 2>nul&&sc delete VMnetBridge >nul 2>nul
net stop vmci >nul 2>nul&&sc delete vmci >nul 2>nul
echo.
sc delete "vstor2-mntapi20-shared" >nul 2>nul
sc delete "VMparport" >nul 2>nul
sc delete VMUSBArbService >nul 2>nul
sc delete VMnetDHCP >nul 2>nul
sc delete "VMware NAT Service" >nul 2>nul
sc delete VMAuthdService >nul 2>nul
sc delete VMnetuserif >nul 2>nul
sc delete VMnetAdapter >nul 2>nul
sc delete vmkbd >nul 2>nul
sc delete vmx86 >nul 2>nul
echo.
pause>nul|echo 卸载完成,最好重新启动一下计算机,因为有些驱动可能需要重启后才能删除......
exit