How to run installer from iso file using C # code

I have created an iso image with the app install folder. I want to initialize the execution of an application form .net code. I used the following code to open an image as a disk, given that file explorer is the default application for opening iso files, then read the disks to check if the file I want to run exists.

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

    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"))
                {
                    MessageBox.Show(diLogicalDrive.Name + "setup.exe");
                    System.Diagnostics.Process.Start(diLogicalDrive.Name + "\\setup.exe");
                    //MessageBox.Show("Logical Drive: " + diLogicalDrive.Name,
                    //                "Logical Drives",
                    //                MessageBoxButtons.OK,
                    //                MessageBoxIcon.Information);
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

      

This code doesn't work if File Explorer is not the default opener application. Also, I have a strong feeling that he is not even getting close to the right path. Any form of help or pointers to help links will be greatly appreciated. Thanks for reading

+3


source to share


1 answer


You can use .NET DiscUtils to extract the file like this:

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...
}

      



Extract the file to a temporary location and then execute it.

0


source







All Articles