开发者

Including an exe in another exe

开发者 https://www.devze.com 2023-04-12 12:44 出处:网络
Assuming i have an executable called mainprogram.exe and another called Update.exe. What I want to acheive is: when Update.exe is started, it replaces mainprogram.exe with, for example, C:\\Pro开发者_

Assuming i have an executable called mainprogram.exe and another called Update.exe. What I want to acheive is: when Update.exe is started, it replaces mainprogram.exe with, for example, C:\Pro开发者_StackOverflow社区gram Files\MyProgram\mainprogram.exe. The point is to include the executable that needs to be replaced in Update.exe so it would be an all-in-one solution.

Also note that I can't create Update.exe that will download the mainprogram.exe from internet, it has to be already included in Update.exe.


In building:

  1. copy UPDATE.EXE to be embedded into the MAIN.EXE as a resource

At runtime (update time)

  1. drop UPDATE.EXE from resource to the hard drive
  2. start UPDATE.EXE with appropriate parameters (command line arguments, depending on the situation)
  3. have UPDATE.EXE try to delete common file that MAIN.EXE will create and leave it opened
  4. when MAIN.EXE exits, handle to the file will be released, allowing UPDATE.EXE to continue doing what it should - replace the MAIN.EXE with new version
  5. start MAIN.EXE from UPDATE.EXE
  6. (optional) delete UPDATE.EXE from MAIN.EXE, as you don't need it for now.


You can use .NET resources and access them via Properties.Resources. If you want to copy the content of a resource to the hard disk you can use System.IO.File.WriteAllBytes.

Adding and Editing Resources (Visual C#)


What you want is called a "Setup Project". This will allow you to bundle any files necessary for such an update to be deployed in such a manner.

Here is the MSDN link for doing this.

In a nutshell, you are creating an installer package, but you can limit the functionality of the installer to replace the designated files only.


You could just use an SFX archive - works pretty much like a setup program and "self extracts". Many archiving programs allow it, or you could just write a setup project in .NET which will do the same thing if you're having to include all the files in the updater anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号