本文介绍了制作将使用 Windows Temp 目录的自解压 zip (SFX) Windows 程序安装程序的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的程序,它包含一个调用 x86 Win32 .dll (Lib.dll) 的 .NET 2.0 exe (Program.exe).

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

我想将它们捆绑到一个名为 Tool.exe 的自解压 zip (SFX) 中Tool.exe 会将文件(Program.exe 和 Lib.dll)解压到 Windows Temp 系统目录中,然后调用 Program.exe

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

这样我就可以提供一个名为 Tool.exe 的单文件 .exe 下载,就用户而言,他们只是在运行 Tool.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 具有 SFX 功能,并且能够自动启动提取的 .exe,但它似乎没有让您选择让它提取到 Windows Temp 目录(您可以指定绝对路径,但 Temp 目录因 Windows 版本而异).此外,它在提取时会弹出一个窗口,这对于我让它看起来像用户刚刚启动我的程序的目标来说太过分了.

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.

或者,有没有办法将本机 Lib.dll 捆绑到我编译的 .NET 可执行文件中,就像资源"一样?

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

我真的很想避免在 MSI 甚至常规 .exe 安装程序上进行完整安装,因为即使使用像 NSIS 这样更简单的安装程序,这样做也很麻烦.

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.

推荐答案

我倾向于只使用 7-zipUPX,按照这些说明进行操作在执行/提取时运行批处理文件.这是我用来构建 EXE 的示例 CMD 脚本,包括 .\bin 目录中的文件:

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

config.txt 文件是这样写的:

The config.txt file reads like this:

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

当然,您的里程可能会有所不同...

Your mileage may vary, of course...

这篇关于制作将使用 Windows Temp 目录的自解压 zip (SFX) Windows 程序安装程序的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 15:35