What's the easiest way to make a self-extracti

2019-04-09 20:32发布

I have a very simple program that consists of a .NET 2.0 exe (Program.exe) that calls an x86 Win32 .dll (Lib.dll).

I would like to bundle these into a single self-extracting zip (SFX) called Tool.exe Tool.exe will extract the files (Program.exe and Lib.dll) into the Windows Temp system directory, and then call Program.exe

This way I can offer a single-file .exe download called Tool.exe and as far as the user is concerned they are just running Tool.exe and not a multi-file program.

WinRAR has SFX capabilities, and ability to auto-launch an extracted .exe, but it doesn't seem to give you the option to let it extract to the Windows Temp dir (you can specify absolute path, but the Temp dir varies depending on what version of Windows). Also, it pops up a window when extracting, and that's overkill for my goals of making it appear like the user is just launching my program.

Alternatively, is there a way to bundle the native Lib.dll into my compiled .NET executable, almost like a "resource"?

I'd really like to avoid making a full on MSI or even a regular .exe installer as that is a pain to do, even with simpler installers like NSIS.

3条回答
一夜七次
2楼-- · 2019-04-09 20:49

NSIS has a useful utility called Zip2Exe. Basically, you give it a zip file, and specify the extraction folder (in your case, $TEMP) and it generates an installer.

You can run such an installer in silent mode (so the user does not actually see the installer). Thus, you might be able to have Tool.exe install and run the program for you. The installer can be an embedded resource which you first write to a temp file before running. Then, the user never knows about any installer. From their point of view, Tool.exe does some work, gives some "please wait..." feedback, and then the actual program you want to run is started and Tool.exe quits.

Edit: In hindsight, you might find it's easier to just extract and run Program.exe (and your dll) from Tool.exe, and then quit Tool.exe. Better still: Let the user run Program.exe (which writes lib.dll to disk before loading it).

I hope this gives you some ideas. Be aware you might have trouble with people's UAC and virus scanners.

查看更多
可以哭但决不认输i
3楼-- · 2019-04-09 21:06

I tend to do this with just 7-zip and UPX, following these directions to make it run a batch file upon execution/extraction. Here's an example CMD script I use to build the EXE including the files in the .\bin directory:

pushd %~dp0
upx --ultra-brute 7zsd.sfx 
cd Bin
..\7za a -mx=9 "..\Program.7z" * 
cd ..
copy /b 7zsd.sfx + Config.txt + Program.7z Program_Name.exe
del Program.7z

The config.txt file reads like this:

;!@Install@!UTF-8!
GUIMode="0"
RunProgram="runme.cmd" 
;!@InstallEnd@!

Your mileage may vary, of course...

查看更多
小情绪 Triste *
4楼-- · 2019-04-09 21:15

DotNetZip can produce an SFX, with a default extract directory. When you create the SFX, specify %TEMP% as the default extract location, and when the SFX is actually run, the variable gets resolved. DotNetZip can also run a program after extracting the SFX, and that program can be one of the things that got extracted.

So you could use DotNetZip to do what you want.

An alternative is explained in this article. It shows how to dynamically make calls into native Win32 DLLs from .NET. Using that technique, you could bundle the library as a resource into your .NET EXE, and then when the .NET EXE starts, extract the Library, and then make the dynamic calls into it.

查看更多
登录 后发表回答