简体   繁体   中英

Passing command line arguments to SFX created with DotNetZip

I created a self-extracting zip using DotNetZip with the following options:

var opts = new SelfExtractorSaveOptions();
opts.RemoveUnpackedFilesAfterExecute = true;
opts.PostExtractCommandLine = "TestApp.exe";
opts.Flavor = SelfExtractorFlavor.ConsoleApplication;
zip1.SaveSelfExtractor("TestAppSFX.exe", opts);

Is it possible to pass command line arguments to my self-extracting zip that will then be passed to the console application that gets invoked after extracting?

Ie, I want to be able to type something like the following:

TestAppSFX.exe -flag

Then, my console application TestApp.exe would receive -flag as an argument.

These arguments will vary depending on usage, so specifying them when I create the SFX is not an option.

I looked at the source code and this doesn't appear to be possible with DotNetZip. I'm now using 7zip to do this as indicated here

I also found this question , which says this is possible with WinRar.

Yes you can pass flags using DotNetZip, but you need to do a little work.

You need to download the source and modify CommandLineSelfExtractorStub.cs to accept you own custom arguments. Once you've done that, you can build it into a new stub exe.

To build your SFX you would do something like this...

byte[] stub = GetStubExecutable(); //read in your new stub file
output.Write(stub, 0, stub.Length);

using (ZipFile zip = new ZipFile())
{
    String[] filenames = System.IO.Directory.GetFiles(Path.Combine(path,FilesFolder)); 
    // Add the rest of they files you'd like in your SFX
    foreach (String filename in filenames)
    {
        ZipEntry e = zip.AddFile(filename, OutputZipFolder);
    }

    zip.Save(output); // save the zip to the outputstream
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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