linux/windows下启用和停止VMware后台服务的脚本
linux平台
将以下代码保存为脚本。(适用于debian
系)
1 #! /bin/bash2 #停止vmware3 sudo service vmware stop4 #停止vmware-USBArbitrator5 sudo service vmware-USBArbitrator stop6 #停止vmware-workstation-server7 sudo service vmware-workstation-server stop8 #关闭相关进程9 sudo killall vmware*
windows平台
将下面的代码保存为xxx.bat
。注意使用的时候要使用管理员权限运行。
1 @echo off 2 for /f "skip=3 tokens=4" %%i in ('sc query "VMAuthdService"') do set "zt=%%i" &goto :next 3 :next 4 if /i "%zt%"=="RUNNING" ( 5 echo 服务VMware Authorization Service正在运行 6 ) else ( 7 echo 服务VMware Authorization Service已停止 8 ) 9 for /f "skip=3 tokens=4" %%i in ('sc query "VMnetDHCP"') do set "zt=%%i" &goto :next 10 :next 11 if /i "%zt%"=="RUNNING" ( 12 echo 服务VMware DHCP Service正在运行 13 ) else ( 14 echo 服务VMware DHCP Service已停止 15 ) 16 for /f "skip=3 tokens=4" %%i in ('sc query "VMware NAT Service"') do set "zt=%%i" &goto :next 17 :next 18 if /i "%zt%"=="RUNNING" ( 19 echo 服务VMware NAT Service正在运行 20 ) else ( 21 echo 服务VMware NAT Service已停止 22 ) 23 for /f "skip=3 tokens=4" %%i in ('sc query "VMUSBArbService"') do set "zt=%%i" &goto :next 24 :next 25 if /i "%zt%"=="RUNNING" ( 26 echo 服务VMware USB Arbitration Service正在运行 27 ) else ( 28 echo 服务VMware USB Arbitration Service已停止 29 ) 30 for /f "skip=3 tokens=4" %%i in ('sc query "VMwareHostd"') do set "zt=%%i" &goto :next 31 :next 32 if /i "%zt%"=="RUNNING" ( 33 echo 服务VVMware Workstation Server正在运行 34 ) else ( 35 echo 服务VMware Workstation Server已停止 36 )37 pause 38 echo 1:启用VM虚拟机服务(VMware Authorization Service、VMware DHCP Service、VMware NAT Service、VMware USB Arbitration Service、VMware Workstation Server)及网络连接(VMware Network 39 Adapter VMnet1、VMware Network Adapter VMnet8) 40 echo 2:禁用VM虚拟机服务(VMware Authorization Service、VMware DHCP Service、VMware NAT Service、VMware USB Arbitration Service、VMware Workstation Server)及网络连接(VMware Network 41 Adapter VMnet1、VMware Network Adapter VMnet8) 42 choice /c:12 /m "根据选项请选择..." 43 if errorlevel 2 goto two 44 if errorlevel 1 goto one 45 :one 46 echo 正在启用服务... 47 net start "VMAuthdService" 48 net start "VMnetDHCP" 49 net start "VMware NAT Service" 50 net start "VMUSBArbService"51 net start "VMwareHostd"52 echo 正在启用网络连接... 53 netsh interface set interface "VMware Network Adapter VMnet1" enable 54 netsh interface set interface "VMware Network Adapter VMnet8" enable 55 echo 网络连接VMware Network Adapter VMnet1、VMware Network Adapter VMnet8启动成功 56 echo 按任意键退出... 57 pause>nul 58 C:\"Program Files (x86)"\VMware\"VMware Workstation"\vmware.exe59 exit 60 :two 61 echo 正在禁用服务服务... 62 net stop "VMAuthdService" 63 net stop "VMnetDHCP" 64 net stop "VMware NAT Service" 65 net stop "VMUSBArbService"66 net stop "VMwareHostd"67 echo 正在禁用网络连接... 68 netsh interface set interface "VMware Network Adapter VMnet1" disable 69 netsh interface set interface "VMware Network Adapter VMnet8" disable 70 echo 网络连接VMware Network Adapter VMnet1、VMware Network Adapter VMnet8禁用成功71 echo 正在结束进程72 taskkill /F /IM vmware-authd.exe /T73 taskkill /F /IM vmnetdhcp.exe /T74 taskkill /F /IM vmnat.exe /T75 taskkill /F /IM vmware-usbarbitrator64.exe /T76 taskkill /F /IM vmware-hostd.exe /T77 taskkill /F /IM vmware-tray.exe /T 78 echo 按任意键退出... 79 pause>nul 80 exit