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.
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 andTool.exe
quits.Edit: In hindsight, you might find it's easier to just extract and run
Program.exe
(and your dll) fromTool.exe
, and then quitTool.exe
. Better still: Let the user runProgram.exe
(which writeslib.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 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:
The config.txt file reads like this:
Your mileage may vary, of course...
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.