我正在尝试自动化VMWare Workstation,我需要实现的功能是:
我正在使用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();
我试图连接工作站时在第二行收到错误。
未处理的类型' System.Exception'发生在 Vestris.VMWareLib.dll
其他信息:无法连接: serviceProviderType ="工作站"主机名="" hostPort = 0用户名="" 超时= 60
使用CLSID检索组件的COM类工厂 {6874E949-7186-4308-A1B9-D55A91F60728}因以下原因失败 错误:80040154未注册类(HRESULT异常: 0x80040154(REGDB_E_CLASSNOTREG))。