日常中很多时候需要用到虚拟机,vbox和vmware都是windows系统下不错的虚
拟机软件,但是因为vbox的虚拟网络参数比较难调一些,所以我选择了使用vmware
虚拟机,在使用中遇到了一些不便,每次开机之后我都要手动打开虚拟机,感
觉很麻烦,于是从网上搜索了一下,通过命令行使用vmware.exe和vmrun.exe这
两个工具,都能实现从命令行启动虚拟机。
我自己使用的是vmrun工具来启动虚拟机的。vmrun的具体操作参数如下:
----------------------------------------------------------------------------
Usage: vmrun [AUTHENTICATION-FLAGS] COMMAND [PARAMETERS]
AUTHENTICATION-FLAGS
--------------------
These must appear before the command and any command parameters.
-h <hostName> (not needed for Workstation)
-P <hostPort> (not needed for Workstation)
-T <hostType> (ws|server|server1|fusion|esx|vc|player)
for example, use '-T server' for VMware Server 2.0
use '-T server1' for VMware Server 1.0
use '-T ws' for VMware Workstation
use '-T ws-shared' for VMware Workstation (shared mode)
use '-T esx' for VMware ESX
use '-T vc' for VMware vCenter Server
-u <userName in host OS> (not needed for Workstation)
-p <password in host OS> (not needed for Workstation)
-vp <password for encrypted virtual machine>
-gu <userName in guest OS>
-gp <password in guest OS>
POWER COMMANDS PARAMETERS DESCRIPTION
-------------- ---------- -----------
start Path to vmx file Start a VM or Team
[gui|nogui]
stop Path to vmx file Stop a VM or Team
[hard|soft]
reset Path to vmx file Reset a VM or Team
[hard|soft]
suspend Path to vmx file Suspend a VM or Team
[hard|soft]
pause Path to vmx file Pause a VM
unpause Path to vmx file Unpause a VM
SNAPSHOT COMMANDS PARAMETERS DESCRIPTION
----------------- ---------- -----------
listSnapshots Path to vmx file List all snapshots in a VM
[showTree]
snapshot Path to vmx file Create a snapshot of a VM
Snapshot name
deleteSnapshot Path to vmx file Remove a snapshot from a VM
Snapshot name
[andDeleteChildren]
revertToSnapshot Path to vmx file Set VM state to a snapshot
Snapshot name
GUEST OS COMMANDS PARAMETERS DESCRIPTION
----------------- ---------- -----------
runProgramInGuest Path to vmx file Run a program in Guest OS
[-noWait]
[-activeWindow]
[-interactive]
Complete-Path-To-Program
[Program arguments]
fileExistsInGuest Path to vmx file Check if a file exists in Guest OS
Path to file in guest
directoryExistsInGuest Path to vmx file Check if a directory exists in Gue
st OS
Path to directory in guest
setSharedFolderState Path to vmx file Modify a Host-Guest shared folder
Share name
Host path
writable | readonly
addSharedFolder Path to vmx file Add a Host-Guest shared folder
Share name
New host path
removeSharedFolder Path to vmx file Remove a Host-Guest shared folder
Share name
enableSharedFolders Path to vmx file Enable shared folders in Guest
[runtime]
disableSharedFolders Path to vmx file Disable shared folders in Guest
[runtime]
listProcessesInGuest Path to vmx file List running processes in Guest OS
killProcessInGuest Path to vmx file Kill a process in Guest OS
process id
runScriptInGuest Path to vmx file Run a script in Guest OS
[-noWait]
[-activeWindow]
[-interactive]
Interpreter path
Script text
deleteFileInGuest Path to vmx file Delete a file in Guest OS
Path in guest
createDirectoryInGuest Path to vmx file Create a directory in Guest OS
Directory path in guest
deleteDirectoryInGuest Path to vmx file Delete a directory in Guest OS
Directory path in guest
listDirectoryInGuest Path to vmx file List a directory in Guest OS
Directory path in guest
CopyFileFromHostToGuest Path to vmx file Copy a file from host OS to guest
OS
Path on host Path in guest
CopyFileFromGuestToHost Path to vmx file Copy a file from guest OS to host
OS
Path in guest Path on host
renameFileInGuest Path to vmx file Rename a file in Guest OS
Original name
New name
captureScreen Path to vmx file Capture the screen of the VM to a
local file
Path on host
writeVariable Path to vmx file Write a variable in the VM state
[runtimeConfig|guestEnv|guestVar]
variable name
variable value
readVariable Path to vmx file Read a variable in the VM state
[runtimeConfig|guestEnv|guestVar]
variable name
VPROBE COMMANDS PARAMETERS DESCRIPTION
--------------- ---------- -----------
vprobeVersion Path to vmx file List VP version
vprobeLoad Path to vmx file Load VP script
'VP script text'
vprobeLoadFile Path to vmx file Load VP file
Path to VP file
vprobeReset Path to vmx file Disable all vprobes
vprobeListProbes Path to vmx file List probes
vprobeListGlobals Path to vmx file List global variables
GENERAL COMMANDS PARAMETERS DESCRIPTION
---------------- ---------- -----------
list List all running VMs
upgradevm Path to vmx file Upgrade VM file format, virtual hw
installTools Path to vmx file Install Tools in Guest
register Path to vmx file Register a VM
unregister Path to vmx file Unregister a VM
listRegisteredVM List registered VMs
deleteVM Path to vmx file Delete a VM
clone Path to vmx file Create a copy of the VM
Path to destination vmx file
full|linked
[Snapshot name]
Examples:
Starting a virtual machine with Workstation on a Windows host
vmrun -T ws start "c:\my VMs\myVM.vmx"
Stopping a virtual machine on an ESX host
vmrun -T esx -h https://myHost.com/sdk -u hostUser -p hostPassword stop "[sto
rage1] vm/myVM.vmx"
Running a program in a virtual machine with Workstation on a Windows host with W
indows guest
vmrun -T ws -gu guestUser -gp guestPassword runProgramInGuest "c:\my VMs\myVM
.vmx" "c:\Program Files\myProgram.exe"
Running a program in a virtual machine with Server on a Linux host with Linux gu
est
vmrun -T server -h https://myHost.com:8333/sdk -u hostUser -p hostPassword -g
u guestUser -gp guestPassword runProgramInGuest "[standard] vm/myVM.vmx" /usr/bi
n/X11/xclock -display :0
Creating a snapshot of a virtual machine with Workstation on a Windows host
vmrun -T ws snapshot "c:\my VMs\myVM.vmx" mySnapshot
Reverting to a snapshot with Workstation on a Windows host
vmrun -T ws revertToSnapshot "c:\my VMs\myVM.vmx" mySnapshot
Deleting a snapshot with Workstation on a Windows host
vmrun -T ws deleteSnapshot "c:\my VMs\myVM.vmx" mySnapshot
Enabling Shared Folders with Workstation on a Windows host
vmrun -T ws enableSharedFolders "c:\my VMs\myVM.vmx"
--------------------------------------------------------------------------
其中的常用参数:
list 显示当前正在运行的虚拟机列表
-T (ws|server|server1|fusion|esx|vc|player) 指定虚拟机的类型
start 启动虚拟机
suspend 暂停虚拟机
使用示例:
前台启动脚本
--------------------------------------------------------------------------
cd /d H:\Installed-soft\VMware Workstation
vmrun -T ws start "h:\virtual machines\nagios_32\nagios_32.vmx"
--------------------------------------------------------------------------
后台启动脚本(使用nogui参数实现)
--------------------------------------------------------------------------
cd /d H:\Installed-soft\VMware Workstation
vmrun -T ws start "h:\virtual machines\nagios_32\nagios_32.vmx" nogui
--------------------------------------------------------------------------
虚拟机暂停脚本(适用于vm8.0)
--------------------------------------------------------------------------cd /d H:\Installed-soft\VMware Workstation
vmrun suspend "h:\virtual machines\nagios_32\nagios_32.vmx"
--------------------------------------------------------------------------
以上的内容,适用于vmware8.0,其他的版本请自行测试。
后续的脚本,会不定时更新。
转载于:https://blog.51cto.com/leaf1024/777252