获取当前正在运行的虚拟机(Vmware Workstation),并对虚拟机进行控制
2016-06-30 16:08
567 查看
vmware workstation 提供了一个命令行工具进行虚拟机管理
C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe
用法如下:
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
.Net中,通过process.start来运行vmrun(带list参数) ,获取该命令的标准输出重定向即可获得当前正在运行的vmware虚拟机列表,然后可根据不同需求(stop、suspend、pause等),带上对应的参数进行虚拟机操作。
Dim strPathShutdown As String = ConfigurationManager.AppSettings("shutdown"),
strPathVmrun As String = ConfigurationManager.AppSettings("vmrun"),
proc As New Process(),
intVM As Integer,
listVM As New List(Of String)
proc.StartInfo = New ProcessStartInfo(strPathVmrun, "list")
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.UseShellExecute = False
proc.Start()
Dim out As String = proc.StandardOutput.ReadToEnd()
MsgBox(out)
listVM = Split(out, vbCrLf).ToList
listVM.RemoveAt(0)
intVM = New System.Text.RegularExpressions.Regex("\d", RegexOptions.IgnoreCase).Match(out).Value
For Each vm As String In listVM
proc.StartInfo.Arguments = String.Format("suspend ""{0}""", vm)
proc.Start()
Next
vmrun的运行结果和对标准输出的解析
C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe
用法如下:
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
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 checkToolsState Path to vmx file Check the current Tools state 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=Snapshot Name] [-cloneName=Name]更多的参数可以直接运行vmrun命令查看(不带参数)
.Net中,通过process.start来运行vmrun(带list参数) ,获取该命令的标准输出重定向即可获得当前正在运行的vmware虚拟机列表,然后可根据不同需求(stop、suspend、pause等),带上对应的参数进行虚拟机操作。
Dim strPathShutdown As String = ConfigurationManager.AppSettings("shutdown"),
strPathVmrun As String = ConfigurationManager.AppSettings("vmrun"),
proc As New Process(),
intVM As Integer,
listVM As New List(Of String)
proc.StartInfo = New ProcessStartInfo(strPathVmrun, "list")
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.UseShellExecute = False
proc.Start()
Dim out As String = proc.StandardOutput.ReadToEnd()
MsgBox(out)
listVM = Split(out, vbCrLf).ToList
listVM.RemoveAt(0)
intVM = New System.Text.RegularExpressions.Regex("\d", RegexOptions.IgnoreCase).Match(out).Value
For Each vm As String In listVM
proc.StartInfo.Arguments = String.Format("suspend ""{0}""", vm)
proc.Start()
Next
vmrun的运行结果和对标准输出的解析
相关文章推荐
- AngularJS 常见面试问题
- linux创建桌面图标,和开始菜单栏图标
- Fail2ban 阻止暴力破解
- DataTables+Struts+Ajax技术的文件下载实现
- STM32的项目文件分组
- 项目二 下
- AndroidSweetSheet:ViewPager的实现(2)
- Linux 网络及服务
- jsp页面报错提示编码错误信息
- 友盟第三方登录
- OpenCV学习笔记(4)——平滑处理图像
- js用到的一些工具方法
- stm32 官方例子main函数最后一段代码#ifdef USE_FULLASSERT
- C#开发可以可视化操作的windows服务
- ListView多布局适配器判断条件
- C3P0------- 一个开源的JDBC连接池
- winpcap编程抓包实例和windump使用
- 自定义Gridview实现拖拉改变顺序 仿新闻频道管理
- 长按条目进行删除
- 一个可以用鼠标改变控件位置和大小的类