这是我用来挂载 ISO 的代码
// With help of WMICodeCreator
ManagementObject mo = new ManagementObject("root\\Microsoft\\Windows\\Storage",
"MSFT_DiskImage.ImagePath='" + isoFile + "',StorageType=1",
null);
// Obtain in-parameters for the method
ManagementBaseObject inParams = mo.GetMethodParameters("Mount");
// Execute the method and obtain the return values.
ManagementBaseObject outParams = mo.InvokeMethod("Mount", inParams, null);
outParams 只返回一个 bool,如此处所述。
如果我发出这个命令:
mo.Get();
string device = mo.GetPropertyValue("DevicePath");
...设备字符串显示\\.\CDROM0
。即使我安装了第二个 ISO,它也会显示此值。