是否有任何组件或类可以让我获得在 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)"}