Click here to Skip to main content
15,849,494 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 Virtual Hosts. my issue is how to shutdown the host:
I tried to write a code to shutdwon the hosts using VIX API in c#, I couldn't find a code to shutdown. All I get is to disconnect them.

Here is my code

    VMWareVirtualHost host = new VMWareVirtualHost();

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


    IVMWareVirtualMachine machine = new VMWareVirtualMachine();

    machine = host.Open("[] Kerio contarol.vmxf");


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

catch(Exception ex)
Updated 11-Apr-15 21:18pm
Joan Magnet 7-Apr-15 11:13am    
Have you tried to do not call host.Disconnect() just after calling host.ConnectToVMWareVIServer(---)?

There is an example in CodeProject.
Member 10685840 8-Apr-15 4:43am    
I have looked at that link before, but it does not illustrate how to connect to a virtual machine in a network remotely neither how to shutdown the host.
Member 10685840 8-Apr-15 5:50am    
I have solved my second issue which i could connect to virtual machine as I was adding the wrong virtual machine configuration file which is ("[] Kerio contarol.vmxf"); while the right path is ([datastore1] Kerio contarol/Kerio contarol.vmx).
Joan Magnet 8-Apr-15 7:24am    
Powering Off a Virtual Machine

Connect to the host on which the virtual machine is located. Refer to Connecting to a Host.
Get a handle to the virtual machine. Refer to Getting a Handle to a Virtual Machine.
Use the virtual machine handle in a call to VixVM_PowerOff().
Example 3-12.

VixError err = VIX_OK;
VixHandle jobHandle = VIX_INVALID_HANDLE;

// Power off the virtual machine.
jobHandle = VixVM_PowerOff(vmHandle,
0, // powerOffOptions,
VIX_INVALID_HANDLE, // propertyListHandle,
NULL, // callbackProc,
NULL); // clientData
err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);
if (VIX_OK != err) {
// Handle the error...
goto abort;
Member 10685840 8-Apr-15 8:49am    
Thank you for your replay, but I have solved the issue on how to shutdown the virtual machine.
Note: powering off the machine is not safe as shutting down.
my code was right, except that i mistaken the configuration path. the right code is as follow:

VMWareVirtualHost host = new VMWareVirtualHost();
host.ConnectToVMWareVIServer("", "root","123456");
IVMWareVirtualMachine machine = new VMWareVirtualMachine();
machine = host.Open("[datastore1] Kerio contarol/Kerio contarol.vmx");
The current problem is how to shutdown the host itself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900