我是c#的首发,我的知识很少。我在c#上创建了一个windows应用程序,远程关闭了我网络中的Windows服务器。我有一个v-center服务器,它托管两个带虚拟机的主机。我可以连接到虚拟机并关闭它们,但我的问题是我试图编写一个代码来使用c#中的VIX API关闭主机本身,但我无法做到。我得到的只是断开它们。我错过了任何其他类或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);
}
答案 0 :(得分:1)
我认为您可以尝试 PowerOff 功能。
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);
}