是否有任何組件或類可以獲取在Hyper-v上運行的所有VM的狀態?我希望能夠列出所有vms及其狀態(停止,運行,暫停等)。如何使用Delphi或C獲取Hyper-v上的虛擬機狀態?
我知道微軟有WMI方法,但我得到的所有樣本都是針對.Net,而沒有針對Delphi。我應該可以將這些類轉換爲Delphi,但如果我可以使用Delphi的某些東西,那將會更容易。
編輯
我有C#示例:
/
/ define the information we want to query - in this case, just grab all properties of the object
ObjectQuery queryObj = new ObjectQuery("SELECT * FROM Msvm_ComputerSystem");
// object for storing WMI connection options
// pass the "user", "password" and "domain" from command-line
// don't hard-code these into the application!
ConnectionOptions connOpts = new ConnectionOptions();
connOpts.Username = user;
connOpts.Authority = "ntlmdomain:" + domain;
connOpts.Password = password;
// management scope object
ManagementScope manScope = new ManagementScope(@"\\RemoteSystem\root\virtualization", connOpts);
// connect and set up our search
ManagementObjectSearcher vmSearcher = new ManagementObjectSearcher(manScope, queryObj);
ManagementObjectCollection vmCollection = vmSearcher.Get();
// loop through the VMs
foreach (ManagementObject vm in vmCollection)
{
// display VM details
Console.WriteLine("\nName: {0}\nStatus: {1}\nDescription: {2}\n",
vm["ElementName"].ToString(),
vm["EnabledState"].ToString(),
vm["Description"].ToString());
}
我嘗試在Visual Studio中運行這個,看看它的工作原理,所以我可以試着翻譯一下到德爾福。但是,即使我更改用戶名,域名和密碼,我仍然有這個錯誤:
{"The RPC server is not available. (HRESULT: 0x800706BA)"}
我不熟悉的WMI方法獲取這些特定的數據,但是在各種語言中有許多WMI示例,而不僅僅是.NET。難道你不能將這些例子中的信息與你在VM交互中找到的.NET特定的例子結合起來嗎? – GolezTrol
有一個關於WMI和Delphi的好博客:http://theroadtodelphi.wordpress.com/ – Andreas
等一下。你說你可以找到很多.Net的例子來說明如何做到這一點。你現在可以用C#而不是僅僅用Delphi來接收答案。那麼你的問題是什麼? –