c# - 无法使用 SevenZipExtractor 解压 .exe(7zip 自解压存档)

标签 c# exe 7zip

使用的库:https://github.com/adoconnection/SevenZipExtractor

       var file = @"C:\Users\PC\Desktop\SelfExtractFile.exe";
       var destination = @"C:\Users\PC\Desktop\";

       using ( ArchiveFile archiveFile = new ArchiveFile(file))
       {
         archiveFile.Extract(destination, true);
       }

我得到::“对象引用未设置到对象的实例。” 存档和条目为空。

该库表示它支持 .exe。

知道如何解决这个问题吗?

最佳答案

SevenZipExtractor库不支持自解压存档(SFX)。它只支持提取标准exe文件。

但是您可以在进程中以静默模式运行自解压存档:

   static void Main(string[] args)
    {
        var file = @"c:\selfextracting.exe";
        var destination = @"C:\Users\PC\Desktop\";

        var output = ExtractSelfExtractingArchive(file, destination);

        Console.WriteLine(output);
    }

    private static string ExtractSelfExtractingArchive(string archiveFilePath, string destination)
    {
        try
        {
            Process process = new Process();
            process.StartInfo.FileName = archiveFilePath;
            process.StartInfo.Arguments = $" -o\"{destination}\" -y";
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

            process.Start();
            string output = process.StandardOutput.ReadToEnd();
            process.WaitForExit();

            return output;
        }
        catch (Exception exception)
        {

            return exception.Message;
        }
    }

关于c# - 无法使用 SevenZipExtractor 解压 .exe(7zip 自解压存档),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72688154/

相关文章:

c# - 如何进行转换 SQL 内部连接查询与 Entity Framework

c# - RegularExpressionAttribute 不使用表达式来测试点 (\.)

c# - OnPropertyChange 触发顺序

Groovy:如何将 .groovy 转换为 .exe

7zip - 如何设置文件属性 7zS.sfx 自解压可执行文件

java - 在java中获取7-Zip信息

带有特殊字符的python 7z密码

c# - C++ NamedPipeClientStream 发送数据

.net - 从压缩的 "zip"文件运行 .Net 应用程序

c# - 如果调试文件夹的其余部分可用,但我的 EXE 运行良好,但不是独立的