繁体   English   中英

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

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

我用应用程序的安装文件夹创建了一个iso映像。 我想从.net代码初始化应用程序的执行。 我一直在使用以下代码将图像作为驱动器打开,因为文件资源管理器是打开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);
        }
    }

如果文件资源管理器不是默认的iso打开应用程序,则此代码可以正常工作。 此外,我有强烈的感觉,它甚至没有接近正确的做法。 非常感谢任何形式的帮助或帮助链接的指针。 谢谢你的阅读

您可以使用.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...
}

将文件解压缩到临时位置,然后执行它。

暂无
暂无

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

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