【发布时间】:2011-10-26 15:43:50
【问题描述】:
是否有任何组件或类可以让我获得在 Hyper-v 上运行的所有 VM 的状态?我希望能够列出所有虚拟机及其状态(停止、运行、暂停等)。
我知道微软有 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 上运行它以查看它是否有效,以便我可以尝试将其翻译到 Delphi。但即使我更改了用户名、域和密码,我仍然收到此错误:
{"The RPC server is not available. (HRESULT: 0x800706BA)"}
【问题讨论】:
-
我不熟悉用于获取这些特定数据的 WMI 方法,但是有许多不同语言的 WMI 示例,不仅是 .NET。您不能将这些示例中的信息与您找到的用于 VM 交互的 .NET 特定示例结合起来吗?
-
有一篇关于WMI和Delphi的好博客:theroadtodelphi.wordpress.com
-
等等。你说你可以找到很多关于如何做到这一点的 .Net 示例。您现在可以接受 C# 中的答案,而不仅仅是 Delphi。那么你的问题是什么?
-
@Rafael Colucci:你能在这里分享你的发现吗?
标签: c# delphi wmi virtualization hyper-v