简体   繁体   中英

How can I connect to vmware using VIX (c# wrapper)

I'm trying to connect to VMWare Player machine using VMWareTasks (http://vmwaretasks.codeplex.com) but throw an error..

// declare a virtual host
using (VMWareVirtualHost virtualHost = new VMWareVirtualHost())
{
    string vmfile = @"D:\SIRETIH-Releases\SIRETIH_Virtual\pc-virtual\siretih.vmx";
    // connect to the host
    virtualHost.ConnectToVMWarePlayer(); // <<-- this line throws an error... 

    using (VMWareVirtualMachine virtualMachine = virtualHost.Open(vmfile))
    {
        virtualMachine.WaitForToolsInGuest();
        virtualMachine.LoginInGuest("siretih", "");
    }
}

I'm using Visual Studio 2010 (C#), VMWareTasks, VmWare Player 4.0.2 build-591240 (Windows OS), Windows 7 ...

virtual machine have vmware tools...

Do I need install anymore dll or api?

No se controló System.Exception
Message=Failed to connect: serviceProviderType="Player" hostName="" hostPort=0 username="" timeout=60
Source=Vestris.VMWareLib
  StackTrace:
en Vestris.VMWareLib.VMWareVirtualHost.Connect(ServiceProviderType serviceProviderType, String hostName, Int32 hostPort, String username, String password, Int32 timeout)
   en Vestris.VMWareLib.VMWareVirtualHost.ConnectToVMWarePlayer(Int32 timeoutInSeconds)
   en Vestris.VMWareLib.VMWareVirtualHost.ConnectToVMWarePlayer()utionContext, ContextCallback callback, Object state)

ConnectToVMWarePlayer() method has just one arg... there is a method "ConnectToVMWareVIServer" but I'm not using vmware server just player...

public void ConnectToVMWarePlayer(
    int timeoutInSeconds
)

A bit late I know, but how about the following way of getting a VMWareVirtualMachine object you can use:

VMWareVirtualMachine virtualMachine = SetupVM(virtualHost, vmfile);

Just do a double check against null to make sure that you have an actual instance you can use. That is how I go about doing it, but maybe my use case is different than yours.

I'm not sure if it is exactly the same, but the line of code you say is throwing an error needs the host and user credentials when connecting to VIServer:

virtualHost.ConnectToVMWareVIServer(VMServerHost, VMServerUserName, VMServerPassword);

Can you provide that information to the VMWareVirtualHost.ConnectToVMPlayer method?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM