Question

I am trying to create a self extracting exe. Creating it is no problem. Where I am facing problems is

  • Setting the extraction path where the exe exists
  • Running the extracted 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

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);
Was it helpful?

Solution

I see two problems.

First, you are calling

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

The AddDirectory() method adds a directory into the zip archive. The overload that accepts 2 inputs, the one you are using, names that directory in the zip archive with the second argument. Therefore after making this call you will have in the zip archive, all the files that can be found in DirectoryPath on your filesystem. The root directory name used in the zip archive will be "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().


Second, according to the documentation, the post-extract command is run

...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".


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. Examine the zip file you produce to make sure it looks like you want it to look. When you get it right, put the SaveSelfExtractor() part back in, and you will have a proper SFX.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top