如何使用C#代码使用File Eplorer打开Iso文件 [英] How Do I Open An Iso File With File Eplorer Using C# Code

查看:152
本文介绍了如何使用C#代码使用File Eplorer打开Iso文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好专家那里。我有一个问题,我需要在iso文件中初始化可执行文件的安装。他跟随代码工作,但不能说很好,因为它显然不是正确使用的代码。



System.Diagnostics.Process.Start(C:\ \ Users\\tjdtud \\Desktop \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ EventArgs e)

{

DriveInfo [] diLocalDrives = DriveInfo.GetDrives();

尝试

{

foreach(diLocalDrives中的DriveInfo diLogicalDrive)

{

if(File.Exists(diLogicalDrive.Name + +setup.exe))

{

System.Diagnostics.Process.Start(diLogicalDrive.Name + +setup.exe);

}

}

}

catch(例外情况)

{

MessageBox.Show(ex.Message) );

}

}



这里的问题是如果文件浏览器不是打开iso文件的默认程序,代码打开默认程序。我已经尝试指定文件浏览器打开iso,即使它不是文件类型的默认程序,但它将任务传递给默认程序。我用以下代码试过这个



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



ProcessStartInfo startInfo = new ProcessStartInfo();

startInfo.FileName =EXPLORER.EXE ;

startInfo.Arguments = file;

Process.Start(startInfo);



任何形式的帮助关于我如何在iso映像的根目录中运行可执行文件或任何可能的方式我可以强制资源管理器打开iso作为驱动器,即使它的默认值非常高。谢谢你的阅读。希望得到你的帮助

解决方案

你首先需要加载ISO来访问里面的文件。



查看以下内容: .NET DiscUtils [ ^ ]



它允许您执行以下操作:



 使用(FileStream isoStream = File.Open( @   C:\ temp \sample.iso))
{
CDReader cd = new CDReader(isoStream, true );
流fileStream = cd.OpenFile( @ Folder \Hello.txt,FileMode 。打开);
// 使用fileStream ...
}


通过.ISO文件,您可能意味着光驱的文件系统的图像。当然,你不能立即使用它。通常,至少有两种不同的方式来访问其文件系统内容。 1)将其安装为虚拟磁盘; 2)解压缩并将文件解压缩到某个目录结构中;如果你需要启动一些应用程序(安装与否);你将无法删除这个目录结构(或其中的一部分),直到执行终止。

(我甚至没有提到基本的机会:在物理上刻录磁盘。)



有关安装方法,请参阅:

https://technet.microsoft.com/en-us/magazine/dn261711.aspx [ ^ ],

https://www.microsoft.com/en-us/download/details.aspx?id=38780 [ ^ ]。



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



对于第二种方法,拆包,我知道的唯一合适的产品目前,如果着名的7-zip: http://en.wikipedia.org/wiki/7-Zip [ ^ ]。



您可以使用名为SevenZipSharp的.NET包装器: http://sevenzipsharp.codeplex.com/ [< a href =http://sevenzipsharp.codeplex.com/target =_ blanktitle =New Window> ^ ]。



-SA

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

解决方案

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:

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


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


这篇关于如何使用C#代码使用File Eplorer打开Iso文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆