先在CentOS上安装ACPID服务

yum -y install acpid
systemctl enable acpid
systemctl start acpid

# CentOS 6
# chkconfig acpid on

然后,建立Windows bat文件,内容如下:

@echo off

d:

cd "D:\Program Files\Oracle\VirtualBox"

VBoxManage.exe controlvm "CentOS" acpipowerbutton

echo.
echo CentOS电源已经关闭
echo.
echo 【按任意键退出】

pause>nul

exit

代码中cd后是virtualbox安装目录,"CentOS"是虚拟主机名,需要实际情况进行修改即可。