我已经用应用程序的安装文件夹创建了一个 iso 镜像。我想通过 .net 代码初始化应用程序的执行。鉴于文件资源管理器是打开 iso 文件的默认应用程序,我一直在使用以下代码将图像作为驱动器打开,然后读取驱动器以检查是否存在我要运行的文件。
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"))
{
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...
}
将文件解压到临时位置,然后执行。
关于c# - 如何使用 C# 代码从 iso 文件运行安装程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29884794/