2012-07-26 90 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    
     } 
    }