简体   繁体   English

如何使用c#代码从iso文件运行安装程序

[英]How to run the installer from an iso file using c# code

I have created an iso image with the installation folder of an application. 我用应用程序的安装文件夹创建了一个iso映像。 I want to intialize the execution of the application form a .net code. 我想从.net代码初始化应用程序的执行。 I have been using the following code to open the image as a drive given that file explorer is the default application for opening iso files, then read the drives to check if there exists the file i want to run. 我一直在使用以下代码将图像作为驱动器打开,因为文件资源管理器是打开iso文件的默认应用程序,然后读取驱动器以检查是否存在我想要运行的文件。

System.Diagnostics.Process.Start("C:\\Users\\tjdtud\\Desktop\\done\\publish.iso"); System.Diagnostics.Process.Start( “C:\\用户\\ tjdtud \\桌面\\完成\\ 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"))
                {
                    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 failes to work if file explorer is not the default iso opening application. 如果文件资源管理器不是默认的iso打开应用程序,则此代码可以正常工作。 Besides i have a strong feeling that it is not even close to the right way of doing it. 此外,我有强烈的感觉,它甚至没有接近正确的做法。 Will very much appreciate any form of help or pointers to help links. 非常感谢任何形式的帮助或帮助链接的指针。 Thank you for reading 谢谢你的阅读

You can use .NET DiscUtils to extract the file as follows: 您可以使用.NET DiscUtils提取文件,如下所示:

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. 将文件解压缩到临时位置,然后执行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM