0

我正在尝试自动化 VMWare Workstation,我需要实现的功能是:

  1. 获取所有虚拟机名称
  2. 停止虚拟机
  3. 启动虚拟机

技术

我正在使用 VMware Workstation 12 和 .Net 2013 (C#)

Vestris.VMWareLib.dll添加参考后我做了什么:

VMWareVirtualHost virtualHost = new VMWareVirtualHost();
// connect to a local (VMWare Workstation) virtual machine
virtualHost.ConnectToVMWareWorkstation();
// open an existing virtual machine
//VMWareVirtualMachine virtualMachine = virtualHost.Open(@"C:\Virtual 
Machines\xp\xp.vmx");

VMWareVirtualMachine virtualMachine = 
virtualHost.Open(@"C:\Users\tabish.mateen\Documents\Virtual Machines\Windows 
7 x64\Windows 7 x64.vmx");


// power on this virtual machine
virtualMachine.PowerOn();
// wait for tools to launch
virtualMachine.WaitForToolsInGuest();
// login to the virtual machine
virtualMachine.LoginInGuest("Administrator", "password");
// run notepad
virtualMachine.RunProgramInGuest("notepad.exe", string.Empty);
// create a new snapshot
string name = "New Snapshot";
// take a snapshot at the current state
virtualMachine.Snapshots.CreateSnapshot(name, "test snapshot");
// power off
virtualMachine.PowerOff();
// find the newly created snapshot
VMWareSnapshot snapshot = virtualMachine.Snapshots.GetNamedSnapshot(name);
// revert to the new snapshot
snapshot.RevertToSnapshot();
// delete snapshot
snapshot.RemoveSnapshot();

尝试连接到工作站时,我在第二条线路上遇到错误。

例外

在 Vestris.VMWareLib.dll 中出现“System.Exception”类型的未处理异常

附加信息:连接失败:serviceProviderType="Workstation" hostName="" hostPort=0 username="" timeout=60

内部异常

由于以下错误,检索具有 CLSID {6874E949-7186-4308-A1B9-D55A91F60728} 的组件的 COM 类工厂失败:80040154 未注册类(HRESULT 异常:0x80040154 (REGDB_E_CLASSNOTREG))。

4

0 回答 0