linux/windows下启用和停止VMware后台服务的脚本

时间:2021-02-06 06:02:26

linux/windows下启用和停止VMware后台服务的脚本

本文由乌合之众 lym瞎编,欢迎转载 blog.cnblogs.net/oloroso
本文由乌合之众 lym瞎编,欢迎转载 my.oschina.net/oloroso

linux平台

将以下代码保存为脚本。(适用于debian系)

 #! /bin/bash
#停止vmware
sudo service vmware stop
#停止vmware-USBArbitrator
sudo service vmware-USBArbitrator stop
#停止vmware-workstation-server
sudo service vmware-workstation-server stop
#关闭相关进程
sudo killall vmware*

windows平台

将下面的代码保存为xxx.bat。注意使用的时候要使用管理员权限运行。

 @echo off
for /f "skip=3 tokens=4" %%i in ('sc query "VMAuthdService"') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo 服务VMware Authorization Service正在运行
) else (
echo 服务VMware Authorization Service已停止
)
for /f "skip=3 tokens=4" %%i in ('sc query "VMnetDHCP"') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo 服务VMware DHCP Service正在运行
) else (
echo 服务VMware DHCP Service已停止
)
for /f "skip=3 tokens=4" %%i in ('sc query "VMware NAT Service"') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo 服务VMware NAT Service正在运行
) else (
echo 服务VMware NAT Service已停止
)
for /f "skip=3 tokens=4" %%i in ('sc query "VMUSBArbService"') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo 服务VMware USB Arbitration Service正在运行
) else (
echo 服务VMware USB Arbitration Service已停止
)
for /f "skip=3 tokens=4" %%i in ('sc query "VMwareHostd"') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo 服务VVMware Workstation Server正在运行
) else (
echo 服务VMware Workstation Server已停止
)
pause
echo 1:启用VM虚拟机服务(VMware Authorization Service、VMware DHCP Service、VMware NAT Service、VMware USB Arbitration Service、VMware Workstation Server)及网络连接(VMware Network
Adapter VMnet1、VMware Network Adapter VMnet8)
echo 2:禁用VM虚拟机服务(VMware Authorization Service、VMware DHCP Service、VMware NAT Service、VMware USB Arbitration Service、VMware Workstation Server)及网络连接(VMware Network
Adapter VMnet1、VMware Network Adapter VMnet8)
choice /c:12 /m "根据选项请选择..."
if errorlevel 2 goto two
if errorlevel 1 goto one
:one
echo 正在启用服务...
net start "VMAuthdService"
net start "VMnetDHCP"
net start "VMware NAT Service"
net start "VMUSBArbService"
net start "VMwareHostd"
echo 正在启用网络连接...
netsh interface set interface "VMware Network Adapter VMnet1" enable
netsh interface set interface "VMware Network Adapter VMnet8" enable
echo 网络连接VMware Network Adapter VMnet1、VMware Network Adapter VMnet8启动成功
echo 按任意键退出...
pause>nul
C:\"Program Files (x86)"\VMware\"VMware Workstation"\vmware.exe
exit
:two
echo 正在禁用服务服务...
net stop "VMAuthdService"
net stop "VMnetDHCP"
net stop "VMware NAT Service"
net stop "VMUSBArbService"
net stop "VMwareHostd"
echo 正在禁用网络连接...
netsh interface set interface "VMware Network Adapter VMnet1" disable
netsh interface set interface "VMware Network Adapter VMnet8" disable
echo 网络连接VMware Network Adapter VMnet1、VMware Network Adapter VMnet8禁用成功
echo 正在结束进程
taskkill /F /IM vmware-authd.exe /T
taskkill /F /IM vmnetdhcp.exe /T
taskkill /F /IM vmnat.exe /T
taskkill /F /IM vmware-usbarbitrator64.exe /T
taskkill /F /IM vmware-hostd.exe /T
taskkill /F /IM vmware-tray.exe /T
echo 按任意键退出...
pause>nul
exit

查看 xxx.bat