简体   繁体   English

提取C#后运行自提取exe-DotNetZip

[英]Run self extracting exe after extraction C# - DotNetZip

I am trying to create a self extracting exe. 我正在尝试创建一个自解压exe。 Creating it is no problem. 创建它没问题。 Where I am facing problems is 我面临的问题是

  • Setting the extraction path where the exe exists 设置exe所在的提取路径
  • Running the extracted exe. 运行解压缩的exe。

For the second part, it is most probable that I must have the extraction path correct. 对于第二部分,最有可能我必须具有正确的提取路径。 I am using the following modified code from DotNetZipLibrary 我正在使用DotNetZipLibrary中的以下修改后的代码

zip.AddDirectory(DirectoryPath, "putty.exe");
zip.Comment = "This will be embedded into a self-extracting console-based exe";
SelfExtractorSaveOptions options = new SelfExtractorSaveOptions();
options.Flavor = SelfExtractorFlavor.ConsoleApplication;
options.DefaultExtractDirectory = "";
options.PostExtractCommandLine = "..\\putty.exe";
options.RemoveUnpackedFilesAfterExecute = true;
zip.SaveSelfExtractor("archive.exe", options);

I see two problems. 我看到两个问题。

First, you are calling 首先,你在打电话

zip.AddDirectory(DirectoryPath, "putty.exe");

The AddDirectory() method adds a directory into the zip archive. AddDirectory()方法将目录添加到zip存档中。 The overload that accepts 2 inputs, the one you are using, names that directory in the zip archive with the second argument. 接受2个输入(您正在使用的输入)的重载将使用第二个参数在zip存档中命名该目录。 Therefore after making this call you will have in the zip archive, all the files that can be found in DirectoryPath on your filesystem. 因此,进行此调用后,您将在zip存档中拥有可以在文件系统上的DirectoryPath找到的所有文件。 The root directory name used in the zip archive will be "putty.exe". zip存档中使用的根目录名称将为“ putty.exe”。 This is at the very least a confusing name for a directory. 至少这是目录的混乱名称。 I think you are probably not intending this. 我认为您可能不打算这样做。

If you want to add a file to the archive, use AddFile(), not AddDirectory(). 如果要将文件添加到存档,请使用AddFile(),而不要使用AddDirectory()。


Second, according to the documentation , the post-extract command is run 其次,根据文档 ,运行post-extract命令

...using the extract directory as the working directory for the process, ... ...使用解压缩目录作为流程的工作目录,...

So if your zip has a file called "putty.exe" in the root of the archive, then the command you want to run is probably "putty.exe", not "..\\putty.exe". 因此,如果压缩文件的根目录中有一个名为“ putty.exe”的文件,则您要运行的命令可能是“ putty.exe”,而不是“ .. \\ putty.exe”。


I suggest that during development, you take out the part that saves to a self-extractor, and replace it with a save to a regular zip file. 我建议在开发过程中,取出保存到自解压器中的部分,并用保存到常规zip文件中的部分替换它。 Examine the zip file you produce to make sure it looks like you want it to look. 检查您生成的zip文件,以确保它看起来像您想要的样子。 When you get it right, put the SaveSelfExtractor() part back in, and you will have a proper SFX. 当您安装正确时,将SaveSelfExtractor()部件放回去,您将获得合适的SFX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM