.net – What’s the easiest way to make a self-extracting zip (SFX) Windows program installer that will use the Windows Temp directory

installationnetwinapiwindows

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.

Best Answer

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