2012-07-26 92 views
-1

这可能是一个简单的问题...我试图提取或解压缩exe文件。我尝试使用winzip手动解压我的exe文件,并提取了很多.mst, .cam, .exe files in a folder cache-2012.1.2.702-win_x64我想通过使用c#编程来实现。使用C#提取.exe文件

我从这个链接此示例代码:http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples

可以anybodey给一些代码,提取或解压缩的exe文件,然后我想从提取的文件推出一个特定的EXE(cache_x86.msi)文件。

下面是一个zip文件,它不是解压缩.exe文件。

var sfxFileToCreate = @"D:\2012.1.2.702\64\cache-2012.1.2.702-win_x64.exe"; 
      using (var zip = new ZipFile()) 
      { 
       var filesToAdd = System.IO.Directory.GetFiles(".", "*.cs"); 
       zip.AddFiles(filesToAdd, ""); 
       var sfxOptions = new SelfExtractorSaveOptions 
       { 
        Flavor = SelfExtractorFlavor.WinFormsApplication, 
        Quiet = false, 
        Copyright = "(c) 2011 Test", 
        Description = "This is a test", 
        SfxExeWindowTitle = "My SFX Window title" 
       }; 
       zip.SaveSelfExtractor(sfxFileToCreate, sfxOptions); 
      } 
+1

你能澄清几点?你想提取任何'EXE'或只是SFX文件?如果是SFX,那么使用哪个工具来生成它。它只是dotnetzip吗? – 2012-07-26 07:48:16

+0

@ Amit Mittal:我试图提取一个exe文件。我想使用任何工具,这将允许我提取exe文件从提取的安装另一个exe文件。 – linguini 2012-07-26 07:50:25

+1

简单地说,不是所有的exe文件都包含其他文件。提取所需文件的解决方案将取决于您拥有的exe文件的性质。例如,如果所需文件是通过dotnetzip创建的SFX归档文件,则它本身就是一个可以使用dotnetzip,7zip等进行提取的归档文件。其他一些exe文件可能根本不是归档文件,并且可能只是将文件嵌入到其文件中资源流(但请记住不是所有的exe文件都嵌入了其他文件)。所以如果你可以在问题中包含这些细节,它将有助于回答它。 – 2012-07-26 08:02:28

回答

1

我建议使用7zip.exe控制台应用程序。您可以使用Process类来启动它。

[编辑]

这里的教程:http://www.dotnetperls.com/7-zip-examples

+0

:请给我看片段,谢谢。 – linguini 2012-07-26 07:29:48

+1

@linguini,这听起来有点像'gimme codez'请求,你不觉得吗?你尝试过自己实施吗?你的执行过程中遇到过一些具体问题吗? – 2012-07-26 07:44:56

+0

@Darin Dimitrov:我没有要求整个代码,我找不到任何东西。我使用的代码制作了一个zip文件。我想提取exe文件从提取的文件中安装另一个exe文件。 – linguini 2012-07-26 07:47:44

1
output = StartProcessing("MySelfExtractExeFile.exe", " /auto " + sOutputFilePath); 

    private string StartProcessing(string sProcessingFile, string Arguments) 
    { 
     try 
     { 
      Process p = new Process(); 
      p.StartInfo.FileName = sProcessingFile;// "cmd.exe"; 
      p.StartInfo.Arguments = Arguments;// " /auto " + sOutputFilePath; 

      p.StartInfo.RedirectStandardOutput = true; 
      p.StartInfo.UseShellExecute = false; 
      //make the window Hidden 
      p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
      p.Start(); 
      string output = p.StandardOutput.ReadToEnd(); 
      p.WaitForExit(); 
      return output; 
     } 
     catch (Exception ex) 
     { 

      return ex    
     } 
    }