Windows bat script file to start VM virtual machine and shut down VM virtual machine

1. Script to start VM virtual machine in the background

Create a VMStart.txt file to start the specified VM virtual machine. The content is as follows. If there is Chinese in the path, select ANSI encoding when storing the txt file, and then modify the suffix of the txt to .bat.

:: 命令行进入E盘VM安装路径
E:
cd "E:\VMware\VMware Workstation" 
:: 启动指定路径下的虚拟机,nogui表示不启动界面,直接在后台启动
vmrun.exe -T ws start "E:\Virtual Machines\CentOS 7 64 位\CentOS 7 64 位.vmx" nogui

You can view the virtual machine running icon in the small tray in the lower right corner of the computer:

 

2. Script to shut down the VM virtual machine

Create a VMStop.txt file to shut down the specified VM virtual machine. The content is as follows. If there is Chinese in the path, select ANSI encoding when storing the txt file, and then modify the suffix of the txt to .bat.

:: 命令行进入E盘VM安装路径
E:
cd "E:\VMware\VMware Workstation" 
:: 关闭指定路径下的虚拟机
vmrun.exe -T ws stop "E:\Virtual Machines\CentOS 7 64 位\CentOS 7 64 位.vmx"

3. Let the VM virtual machine start automatically and shut down automatically.

WIN+R opens the run panel and enter:

gpedit.msc

Open the Local Group Policy Editor

Double-click login or logout to open the properties panel, and add the script files you just wrote in the login and logout properties respectively.

 

 

Guess you like

Origin blog.csdn.net/D_lunar/article/details/127299775