Windows批处理完成虚拟机开启与关闭

::This script is for virtual machine start and stop
::the power on or off must send
::the machine name must start with vm and must send to this script
::next example is unbuntu 12 and mac 10.9
::write in 2018-04-07 by Echo
::all copyright beyong to Echo

set machine_name=%1
set machine_switch=%2
set mac_10_9_path=I:\Virtual Machines\OS X 10.9
set ubuntu_12_path=I:\Virtual Machines\Ubuntu
set hard_cfg=""
if "%machine_switch%"=="" (
echo "plese type the machine switch first"
) else (
if %machine_switch%==stop (
	set hard_cfg=hard
	set machine_switch=stop
) else if %machine_switch%==run (
	set hard_cfg=nogui
	set machine_switch=start
)
)
:: echo %hard_cfg%

:: echo %machine_name%
if "%machine_name%"=="" (
echo "plese type the machine name first"
) else (
if %machine_name%==ios (
	set machine_name=%ubuntu_12_path%\OS X 10.9.vmx
) else if %machine_name%==ubuntu (
	set machine_name=%ubuntu_12_path%\UBUNTU.VMX
)
)
:: echo %machine_name%
:: pause

vmrun %machine_switch% "%machine_name%" %hard_cfg%

:: 基本命令:
:: vmrun -T ws start "/opt/VMware/win2k8r2.vmx" nogui
:: 启动无图形界面虚拟机  (-T 是区分宿主机的类型,ws|server|server1|fusion|esx|vc|player,可能比较常用的是ws、esx和player,不过我没有加-T在Workstation也能正常运行, 可能esx和server就需要了)
:: vmrun start "/opt/VMware/win2k8r2.vmx" gui
:: 启动带图形界面虚拟机
:: vmrun stop "/opt/VMware/win2k8r2.vmx"hard | soft
:: 强制关闭虚拟机(相当于直接关电源) | 正常关闭虚拟机
:: vmrun reset "/opt/VMware/win2k8r2.vmx" hard | soft
:: 冷重启虚拟机 | 热重启虚拟机
:: vmrun suspend  "/opt/VMware/win2k8r2.vmx" hard | soft
:: 挂起虚拟机(可能相当于休眠)
:: vmrun pause  "/opt/VMware/win2k8r2.vmx"
:: 暂停虚拟机
:: vmrun unpause  "/opt/VMware/win2k8r2.vmx"
:: 停止暂停虚拟机    
:: vmrun list 
:: 列出正在运行的虚拟机
:: ps aux | grep vmx 
:: 另一种查看正在运行虚拟机的方法

:: vmrun -T ws snapshot "/opt/VMware/win2k8r2.vmx" snapshotName
:: 创建一个快照
:: vmrun -T ws reverToSnapshot "/opt/VMware/win2k8r2.vmx" snapshotName
:: 从一个快照中恢复虚拟机
:: vmrun -T ws listSnapshots "/opt/VMware/win2k8r2.vmx"
:: 列出虚拟机快照数量及名称
:: vmrun -T ws deleteSnapshot "/opt/VMware/win2k8r2.vmx"
:: snapshotName 删除一个快照

:: 创建快照时最好停止虚拟机再创建,听说这样创建的快照比运行虚拟机时要小很多,未验证。


:: 当然命令还有很多,具体可以通过vmrun --help自行查询,linux和windows的命令格式是一样的。


猜你喜欢

转载自blog.csdn.net/cainiao2013/article/details/79844818