Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
Hello experts out there. I have a problem where i need to initialize the installation of an executable file inside an iso file. he following code works but cant say just fine since it it obviously not the right code to be using.

System.Diagnostics.Process.Start("C:\\Users\\tjdtud\\Desktop\\done\\publish.iso")

private void button1_Click(object sender, EventArgs e)
{
DriveInfo[] diLocalDrives = DriveInfo.GetDrives();
try
{
foreach (DriveInfo diLogicalDrive in diLocalDrives)
{
if (File.Exists(diLogicalDrive.Name + + "setup.exe"))
{
System.Diagnostics.Process.Start(diLogicalDrive.Name + + "setup.exe");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

The problem here is that if file explorer is not the default program for opening iso files, the code openes the default program. I've tried specifying the file explorer to open the iso even when it is not default program for the file type but it passed the task to the default program. I have tried this with the following code

string file = "C:\\Users\\tjdtud\\Desktop\\done\\publish.iso";

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "EXPLORER.EXE";
startInfo.Arguments = file;
Process.Start(startInfo);

Any form of help on how i can run the executable in the root directory of an iso image or any possible way i can force the explorer to open the iso as a drive even when its not default is highly appreciated. Thank you for reading. Hoping to get help from you
Posted

You basically need to "load the ISO" first to access the files contained inside.

Have a look at the following: .NET DiscUtils[^]

It will allow you to do the following:

C#
using (FileStream isoStream = File.Open(@"C:\temp\sample.iso"))
{
  CDReader cd = new CDReader(isoStream, true);
  Stream fileStream = cd.OpenFile(@"Folder\Hello.txt", FileMode.Open);
  // Use fileStream...
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Apr-15 22:10pm    
5ed.
—SA
Member 10558843 28-Apr-15 5:35am    
I have done this but this does not seem to invoke the opening of the file. instead it just remain silent after running the line
Stream fileStream = cd.OpenFile(@"Folder\Hello.txt", FileMode.Open);

Is there a way to invoke the actual opening of the file from here
Gideon van Dyk 28-Apr-15 18:41pm    
The problem with working on ISO's in code behind is that you will only be able to access the files to read content, not execute them. To achieve that, you would need to access an Operating System Level Image Mounting Utility with API access.

To see mounting images via PowerShell -> External Reference[^]

For the rest, there's not a lot out there to assist in this. Sorry.
By .ISO file you probably mean the image of a file system of an optical drive. Of course, you cannot use it immediately. Generally, there are at least two different ways to access its filesystem content. 1) mount it as a virtual disk; 2) unpack it and extract the files into some directory structure; if you need to start some application (installation or not); you won't be able to delete this directory structure (or part of it), until execution is terminated.
(I did not even mention the basic opportunity: to burn the disk physically.)

For mounting approach, please see:
https://technet.microsoft.com/en-us/magazine/dn261711.aspx[^],
https://www.microsoft.com/en-us/download/details.aspx?id=38780[^].

In PowerShell: https://technet.microsoft.com/en-us/library/hh848706.aspx[^].

For second approach, unpacking, the only suitable product I know at the moment if famous 7-zip: http://en.wikipedia.org/wiki/7-Zip[^].

You can use this .NET wrapper called SevenZipSharp: http://sevenzipsharp.codeplex.com/[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900