使用C#解压缩.exe文件

时间:2012-07-26 07:24:36

标签: c# extract unzip

这可能是一个简单的问题......我正在尝试提取或解压缩exe文件。我尝试使用winzip手动解压缩我的exe文件,并提取了许多.mst, .cam, .exe files in a folder cache-2012.1.2.702-win_x64我想通过使用c#进行语法编写。

我从此链接获得了此示例代码: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);
            }

2 个答案:

答案 0 :(得分:1)

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

[编辑]

以下是教程:http://www.dotnetperls.com/7-zip-examples

答案 1 :(得分: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            
        }
    }
相关问题