This is the code that I am using to mount the 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);
The outParams just returns a bool as documented here.
If I issue this command:
mo.Get();
string device = mo.GetPropertyValue("DevicePath");
... the device string shows \\.\CDROM0. It shows this value even if I mount a second ISO.
I found a solution in a C++ project created by Jim Dale MountISO.wmi on GitHub
Here is my final C# class for automated mounting and unmounting iso images in Windows 8+ and retrieving the auto-mounted drive letter. It is dramatically faster and more reliable than the typical PowerShell method.