使用的库: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/