Is it possible to create a self-extracting archive which will run a specific file when unzipped?

大城市里の小女人 提交于 2019-12-11 03:48:26

问题


For example, I want to put a deployment of an application which includes setup.exe into a self-extracting archive. When the user executes the self-extracting archive it'll unzip the contents to a temp folder and run setup.exe.

Is this possible? If so, any examples?


回答1:


yes, that's one of the things you can do with DotNetZip.

The doc page provides an example.
SaveSelfExtractor Method (exeToGenerate, options)

string DirectoryPath = "c:\\Documents\\Project7";
using (ZipFile zip = new ZipFile())
{
    zip.AddDirectory(DirectoryPath, System.IO.Path.GetFileName(DirectoryPath));
    zip.Comment = "This will be embedded into a self-extracting WinForms-based exe";
    var options = new SelfExtractorSaveOptions
    {
      Flavor = SelfExtractorFlavor.WinFormsApplication,
      DefaultExtractDirectory = "%USERPROFILE%\\ExtractHere",
      PostExtractCommandLine = ExeToRunAfterExtract,
      SfxExeWindowTitle = "My Custom Window Title",
      RemoveUnpackedFilesAfterExecute = true
    };
    zip.SaveSelfExtractor("archive.exe", options);
}


来源:https://stackoverflow.com/questions/11408790/is-it-possible-to-create-a-self-extracting-archive-which-will-run-a-specific-fil

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!