linux/windows下启用和停止VMware后台服务的脚本
linux/windows下启用和停止VMware后台服务的脚本
本文由乌合之众 lym瞎编,欢迎转载 blog.cnblogs.net/oloroso
本文由乌合之众 lym瞎编,欢迎转载 my.oschina.net/oloroso
linux平台
将以下代码保存为脚本。(适用于debian
系)
1 #! /bin/bash 2 #停止vmware 3 sudo service vmware stop 4 #停止vmware-USBArbitrator 5 sudo service vmware-USBArbitrator stop 6 #停止vmware-workstation-server 7 sudo service vmware-workstation-server stop 8 #关闭相关进程 9 sudo killall vmware*
将以下代码保存为脚本。(适用于archlinux
系)
1 if [ $# -ne 1 ] || ([ $1 != "start" ] && [ $1 != "stop" ]); then 2 echo "请使用 start 或 stop 来进行开启或关闭" 3 exit 0 4 fi 5 sudo systemctl $1 vmware-hostd.service 6 sudo systemctl $1 vmware-authd.service 7 sudo systemctl $1 vmware-hostd-certificates.service 8 sudo systemctl $1 vmware-networks.service 9 sudo systemctl $1 vmware-networks-configuration.service 10 sudo systemctl $1 vmware-usbarbitrator.service 11 12 if [ $1 == "stop" ]; then 13 sudo killall vmware* 14 fi
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.exe 59 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 /T 73 taskkill /F /IM vmnetdhcp.exe /T 74 taskkill /F /IM vmnat.exe /T 75 taskkill /F /IM vmware-usbarbitrator64.exe /T 76 taskkill /F /IM vmware-hostd.exe /T 77 taskkill /F /IM vmware-tray.exe /T 78 echo 按任意键退出... 79 pause>nul 80 exit