批处理管理VM虚拟机服务

===========================================================================
最近倒腾VM虚拟机,不用的时候希望关闭VM虚拟机有关服务
网搜相关命令,写了一个批处理
echo 后面加的是提示语,随便写
总之代码简单来说就是这样了。
这样两个简单的批处理文件,就解决这些问题了。
(PS:如果Win7系统下运行请右键选择 以管理员身份运行 否则将会出现错误5)
===========================================================================
===========================================================================
1、启动服务
===========================================================================
@echo off
echo 正在启用服务…
net start “VMAuthdService”
net start “VMnetDHCP”
net start “VMware NAT Service”
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启动成功
pause
===========================================================================
2、禁止服务
===========================================================================
@echo off
echo 正在禁用服务服务…
net stop “VMAuthdService”
net stop “VMnetDHCP”
net stop “VMware NAT Service”
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禁用成功
pause
===========================================================================
3、如果还麻烦可以把这两个合并成一个:
===========================================================================
@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已停止)
pause
echo 1:启用VM虚拟机服务(VMware Authorization Service、VMware DHCP Service、VMware NAT Service)及网络连接(VMware Network Adapter VMnet1、VMware Network Adapter VMnet8)
echo 2:禁用VM虚拟机服务(VMware Authorization Service、VMware DHCP Service、VMware NAT Service)及网络连接(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”
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
exit
:two
echo 正在禁用服务服务…
net stop “VMAuthdService”
net stop “VMnetDHCP”
net stop “VMware NAT Service”
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 按任意键退出…
pause>nul
exit

点击数:45

留下评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

返回顶部