1

I am a starter in c# and I have a small knowledge. I have made a windows application on c# that shutdwon windows servers in my network remotely. I have a v-center server that hosts two Hosts with virtual machines. I could connect to the virtual machines and shut them down but my issue is I tried to write a code to shutdwon the host itself using VIX API in c#, but I couldn't. All I get is to disconnect them. Am I missing any other class or sdks???

        try
        {
            VMWareVirtualHost host = new VMWareVirtualHost();

            host.ConnectToVMWareVIServer("172.16.1.72", "root","123456");

            //host.Disconnect();

            IVMWareVirtualMachine machine = new VMWareVirtualMachine();

            machine = host.Open("[datastore1] Kerio contarol/Kerio contarol.vmx");

            machine.ShutdownGuest();

            if (machine.IsRunning == true)
            {
                MessageBox.Show("Machine is running");
            }
            else
            {
                MessageBox.Show("Machine is not rinning");
            }

        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
Jaz
  • 689
  • 1
  • 5
  • 11

1 Answers1

1

I think that you can try the PowerOff function.

    try
    {
        VMWareVirtualHost host = new VMWareVirtualHost();

        host.ConnectToVMWareVIServer("172.16.1.72", "root","123456");

        //host.Disconnect();

        IVMWareVirtualMachine machine = new VMWareVirtualMachine();

        machine = host.Open("[datastore1] Kerio contarol/Kerio contarol.vmx");

        machine.PowerOff();

        if (machine.IsRunning == true)
        {
            MessageBox.Show("Machine is running");
        }
        else
        {
            MessageBox.Show("Machine is not rinning");
        }

    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
Angus Chung
  • 1,547
  • 1
  • 11
  • 13
  • Thanks for your replay. Actually I forgot to add the code that shutdown the machine. I edited my post and added the code. In fact, I can shutdown the virtual machine. But my problem is, how to shutdown the Host itself. – Jaz Apr 12 '15 at 06:02