简体   繁体   English

自删除可执行文件(卸载程序)

[英]Self Deleting Executable (Uninstaller)

I'm trying to make an uninstaller.我正在尝试制作卸载程序。 I basically need to be able to remove a directory in the program files that contains the uninstaller.我基本上需要能够删除程序文件中包含卸载程序的目录。

I was thinking to have the uninstaller create a copy of itself to the temp folder, then have the uninstaller running from the program folder open the uninstaller in temp and close itself where it continues the uninstall.我正在考虑让卸载程序在临时文件夹中创建自己的副本,然后让从程序文件夹运行的卸载程序在临时文件夹中打开卸载程序并在继续卸载的地方关闭自身。

Problem is, how do I delete the uninstaller in the temp folder...问题是,如何删除临时文件夹中的卸载程序...

Check out: https://www.catch22.net/tuts/win32/self-deleting-executables查看: https ://www.catch22.net/tuts/win32/self-deleting-executables

He has multiple solutions - but mostly aimed at C++ code.他有多种解决方案——但主要针对 C++ 代码。

I am currently trying to implement the "DELETE_ON_CLOSE" method in C#.我目前正在尝试在 C# 中实现“DELETE_ON_CLOSE”方法。

A comment to all the nay-sayers: MSI does not solve this problem in all cases.对所有反对者的评论: MSI 并不能在所有情况下解决这个问题。 In my case, my application needs to install to a network folder, where any network user can run the app.在我的例子中,我的应用程序需要安装到一个网络文件夹,任何网络用户都可以在其中运行该应用程序。 It also needs to support upgrades and uninstalls from any network workstation - not necessarily the same workstation that installed the app.它还需要支持从任何网络工作站进行升级和卸载——不一定是安装该应用程序的同一工作站。 This means I cannot register an Uninstaller into the Add/Remove Programs list on the local machine.这意味着我无法将卸载程序注册到本地机器上的添加/删除程序列表中。 I must create an Uninstall.exe that is dropped into the install folder.我必须创建一个放入安装文件夹的 Uninstall.exe。 MSI does not support that, so I have to write my own. MSI 不支持那个,所以我必须自己写。

Even though I agree with everyone saying you shouldn't do that, what you can do is:尽管我同意大家说你不应该那样做,但你可以做的是:

  1. Have your program create an executable (and config file) in the temporary folder of the OS it's working on.让您的程序在其正在运行的操作系统的临时文件夹中创建一个可执行文件(和配置文件)。
  2. Have your program start it as an independent process, then exit.让您的程序将其作为独立进程启动,然后退出。
  3. That executable then calls back the actual setup stuff.该可执行文件然后回调实际的设置内容。
  4. Once the setup is done, the temporary executable can delete the setup files.安装完成后,临时可执行文件可以删除安装文件。
  5. Since the only trace of your program is now in the temp folder, it will eventually get cleared automatically.由于您的程序的唯一痕迹现在位于临时文件夹中,因此它最终会自动清除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#卸载程序正在删除我在安装时创建的注册表项 - C# uninstaller is deleting registry keys I created when installing 为mac创建一个自包含的可执行文件 - Making a self contained executable for mac 删除可执行文件后设置会发生什么? - What happens with settings after deleting the executable file? 引用的项目是一个非独立的可执行文件。 自包含的可执行文件不能引用非自包含的可执行文件 - The referenced project is a non self-contained executable. A non self-contained executable cannot be referenced by a self-contained executable .NET反射的自动克隆可执行文件 - Self-cloning executable with .NET reflection 使用C#进行自解压可执行 - Making self-extracting executable with C# 将二进制文件提取到的位置,在一个自包含的可执行文件中 - Where binary is extracted to, in a self contained executable C#中的自删除应用程序在一个可执行文件中 - Self deletable application in C# in one executable EF Core 删除对自身的引用而不删除 - EF Core Remove Reference to Self without deleting .NET 6.0 控制台应用程序作为独立的单文件可执行文件 - .NET 6.0 Console app as a self-contained single file executable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM