What is the easiest way to make a self-extracting zip (SFX) installer for Windows programs that will use the Windows Temp directory?

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

I would like to combine them into one 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

Thus, I can offer a single-file .exe download called Tool.exe, and as far as the user is concerned, they just run Tool.exe, and not a program with several files.

WinRAR has SFX capabilities and the ability to automatically run the extracted .exe file, but it does not seem to give you the ability to allow it to be extracted to the Windows Temp directory (you can specify the absolute path, but Temp dir depends on the version of Windows). In addition, it extracts the window upon extraction, and this superfluous for my purposes to make it look like a user just launches my program.

Alternatively, is there a way to associate the native Lib.dll with my compiled .NET executable, almost like a β€œresource”?

I would really like for me not to make a full-fledged MSI or even a regular .exe installer, since it hurts to do this even with simpler installers like NSIS.

+4
source share
3 answers

I usually do this with 7-zip and UPX , following to get it to run the batch file on execution / extraction . Here is an example CMD script that I use to build the EXE, including the files in the directory. \ Bin:

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 is read as follows:

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

Your mileage may vary, of course ...

+9
source

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

You can run such an installer in silent mode (so that the user does not actually see the installer). Thus, you can have Tool.exe install and run the program for you. The installer may be an embedded resource that you first write to a temporary 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 ...", and then the actual program that you want to run is launched, and Tool.exe terminates.

Edit: In retrospect, it might be easier for you to simply extract and run Program.exe (and your dll) from Tool.exe , and then exit Tool.exe . Even better: let the user run Program.exe (which writes lib.dll to disk before loading).

Hope this gives you some ideas. Keep in mind that you may have problems with UAC people and antivirus scanners.

+1
source

DotNetZip can create SFX with the default extraction directory. When you create SFX, specify% TEMP% as the default extraction location, and when SFX is actually running, the variable will be resolved. DotNetZip can also run the program after extracting SFX, and this program may be one of the things that were extracted.

So you can use DotNetZip to do what you want.

The alternative is explained in this article . It shows how to dynamically make calls to the native Win32 libraries from .NET. Using this technique, you can combine the library as a resource in the .NET EXE, and then when the .NET EXE starts up, extract the library and then make dynamic calls.

0
source

Source: https://habr.com/ru/post/1380679/


All Articles