如何C ++二进制取代自己? [英] How can a C++ binary replace itself?

查看:132
本文介绍了如何C ++二进制取代自己?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更通用的设计环境中提出此问题 。现在,我想谈谈具体细节。

I asked this question in a more general design context before. Now, I'd like to talk about the specifics.

想象一下我有 app.exe 运行。它将 update.exe 下载到同一个文件夹中。如何 app.exe copy update.exe app.exe ?我在一个C ++语境专门询问。我需要某种第三中介应用程序吗?我需要担心文件锁定吗?什么是二进制更新本身最有力的方法(禁止令人讨厌的IT人员有极端的文件权限)?理想情况下,我想看到便携式解决方案(Linux + OSX),但Windows是主要目标。

Imagine that I have app.exe running. It downloads update.exe into the same folder. How would app.exe copy update.exe over the contents of app.exe? I am asking specifically in a C++ context. Do I need some kind of 3rd mediator app? Do I need to worry about file-locking? What is the most robust approach to a binary updating itself (barring obnoxious IT staff having extreme file permissions)? Ideally, I'd like to see portable solutions (Linux + OSX), but Windows is the primary target.

推荐答案


  1. 将您运行的 app.exe 移动/重命名为 app_old.exe

  2. 将您下载的 update.exe 移至/重命名为 app.exe

  3. 下次启动应用程式时,系统会使用更新

  1. Move/Rename your running app.exe to app_old.exe
  2. Move/Rename your downloaded update.exe to app.exe
  3. With the next start of your application the update will be used

重命名正在运行的ie即被锁定的dll / exe不是在Windows下的问题。

Renaming of a running i.e. locked dll/exe is not a problem under windows.

这篇关于如何C ++二进制取代自己?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆