Does .Net have tools for mounting iso disk images?
- Thank! I realized that it turned out to be a lot of possibilities: both Win32 and PowerShell, and without mounting, just read / write with DiscUtils. - Igor
- A daw can only be one? But it may happen that in different comments the answers are the same in importance. - igor
- Stack Overflow format assumes the adoption of only one most correct decision. - Nicolas Chabanovsky ♦
4 answers
Windows 8 / 8.1 / 10 has built-in support for mounting an ISO by calling AttachVirtualDisk .
But from C # it is easiest to mount the disk by calling Powershell ( nuget package ) - Mount-DiskImage
using System.Management.Automation; namespace IsoMountTest { internal class Program { private static void Main(string[] args) { var isoPath = @"C:\Foo\bar.iso"; using (var ps = PowerShell.Create()) { ps.AddCommand("Mount-DiskImage").AddParameter("ImagePath", isoPath).Invoke(); } } } } en-SO: Is there any special API in Windows 8 to Mount ISO files?
- You also need to connect the System.Management.Automation assembly (from the system or via nuget ). - VladD
- @VladD yes, there was a link to nuget in the answer, but she was well hidden :) - PashaPash ♦
- Hmm, really, was :) I did not notice. - VladD
You cannot implement disk mounting with .NET means (you need a driver, but drivers don't write to .NET). But you can find an external program and run it by telling it to mount the disk.
An external program is usually Process.Start via Process.Start .
By the way, if you simply "run" the .iso file, then with the installed program for mounting images there is a good chance that the image will be mounted.
- it's worth adding that Win8 / 8.1 / 10 can mount iso without third-party programs. - PashaPash ♦
For this there is DiscUtils , IsoCreator , IsoCS also.
- Denis, well, and how to mount an image there? :) - Pavel Mayorov
- @PavelMayorov on the first link there is a piece of code) - Denis
- Denis, there is no piece of code that would mount . Only creation and reading. - Pavel Mayorov
If you need to mount an ISO image to read the contents, then there is no need to mount it, because the contents of the ISO file can be read like this:
using (FileStream isoStream = File.Open(@"C:\sample.iso")) { CDReader cd = new CDReader(isoStream, true); Stream fileStream = cd.OpenFile(@"Folder\Hello.txt", FileMode.Open); // ... } This code works thanks to the DiscUtils project, in which there is support for ISO files, as well as for virtual machines there is support: VHD, VDI, XVA, VMDK and many others.
Pages to download DiscUtils:
http://www.nuget.org/packages/Discutils/
http://discutils.codeplex.com/
- I see the reading of the file from the image - but I do not see the mount. - Pavel Mayorov
- Do you think the purpose of the mount is in the mount itself? :) - Box
- The purpose of the mount is to give access to the file to other programs that are not aware of either the disk images or the mount. - Pavel Mayorov
- Do you think the questioner is developing a mount manager? :) Perhaps, but unlikely, because Windows has the necessary utilities. I think the author wants to get access to the ISO from his program. - Box
- @Box if you think that the author needs not to mount an ISO, but to solve some other problem - specify this in the comments to the question - PashaPash ♦