Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the easiest way to make a self-extracting zip (SFX) Windows program installer that will use the Windows Temp directory?

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.

like image 938
jpeskin Avatar asked Dec 27 '22 11:12

jpeskin


2 Answers

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

like image 63
ewall Avatar answered Mar 30 '23 00:03

ewall


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.

like image 29
Charlie Salts Avatar answered Mar 30 '23 00:03

Charlie Salts