dcsimg
Results 1 to 20 of 20

Thread: overwriting your program while it is running.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    154

    overwriting your program while it is running.

    This sounds impossible to me, but i need to do it somehow. Could anybody tell me how I would go about overwriting my program which is running at the time?

  2. #2
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    cant do it...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    Hyperactive Member techman2553's Avatar
    Join Date
    Mar 2001
    Location
    <- To your left.
    Posts
    362
    If you are trying to create a self-updating program, you will probably need to write two programs. Have the main program start an update utility then unload itself. The update utility will exchange EXE's then launch the main program again, then close itself.

    What are you trying to do ??
    ----------

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    154
    thats exactly what i am doing, an auto update.. i just wanted to stick with 1 exe though... anyways, thanks for the help.

  5. #5
    Hyperactive Member techman2553's Avatar
    Join Date
    Mar 2001
    Location
    <- To your left.
    Posts
    362
    Here is an example of a self updating program that uses only one EXE (sort of).

    You can thank chris and lord_dude for the suggestions.

    You can embed a small EXE inside of a main EXE by placing it as a custom resource in a resource file. The resource data can then be copied to a byte array, then written to file to create a second EXE (temporarily). This second EXE can force the main app to close, switch out the old version main app EXE with the new one, then restart the main app again.

    The included zip file contains 2 exe files and the project files in their own folders.

    The EXE's are:

    MyProgram.exe
    MyProgram_Upgrade.exe

    MyProgram_Upgrade.exe is the upgrade to MyProgram (Version2).

    Run the MyProgram.exe and click on the "Check For UpGrade" button. If the program finds the MyProgram_Upgrade.exe, it will ask if you want to upgrade to it. Click yes, and the main app will spawn a temporary Update Utility, close down, then the new version will open up, and remove the Upgrade Utility. When you are done, all you should have is the new MyProgram EXE.

    You can look through the source code to understand how I got all of this to work.

    The resource file can only handle files up to 64K. If you wanted to embed a larger file, you can use my other crazy (and laughable) technique. Check out the link:

    http://www.vbforums.com/showthread.p...794#post367794

    I hope this helps !!!
    Attached Files Attached Files
    ----------

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    154
    Thank you thank you thank you thank you thank you.

  7. #7
    Hyperactive Member techman2553's Avatar
    Join Date
    Mar 2001
    Location
    <- To your left.
    Posts
    362
    your welcome your welcome your welcome your welcome your welcome !!
    ----------

  8. #8
    Lively Member
    Join Date
    Apr 2001
    Location
    Utah, USA
    Posts
    121
    If in NT it can be done, lets see where did I put that

    [goes off to look]

    Here it is:
    http://support.microsoft.com/support.../Q228/9/30.asp
    Josh -- Name
    Zevlag13 -- AIM

    www.WotsIt.org for all your file format spec questions!

  9. #9
    Lively Member
    Join Date
    Oct 2001
    Posts
    105
    Yeah, but InUse only does the update after it reboots, so its no good for replacing regular programs and stuff, and drive the users nuts by rebooting.

  10. #10
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    you can have your program right a batch file before closing to do the copying.

  11. #11
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    On theory it sould be very possible, copy the program to mem and execute it there, when the exe were updated then close the program from mem and exec the one on hdd.

    But no clue how to do it!
    I'v also made a self updating program, i used a *.bat file to do it, fast and easy
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  12. #12
    Lively Member vbgamer45's Avatar
    Join Date
    Sep 2004
    Posts
    67
    On pscode there is an excellent tutorial made by my good friend Alex

    Delete a file in use - Run an EXE in another process' memory - EXE Hijacking

    http://www.pscode.com/vb/scripts/Sho...44907&lngWId=1
    Semi VB Decompiler 0.07 Getting better everyday
    http://www.visualbasiczone.com/produ...ivbdecompiler/
    VisualBasicZone
    http://www.visualbasiczone.com
    EasyPHPBB.com
    Free PHPBB forums the quick and easy way!

  13. #13
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    That source look great, but i still don't understand how to use it, i'm a noob on Hijacking, never did and never understood it well

    But if it works..damn what a nice job there!
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  14. #14
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457
    I'v also made a self updating program, i used a *.bat file to do it, fast and easy
    Any chance of sharing that TDQWERTY ?
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  15. #15
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    it's very easy, on program unload shell the .bat file...

    update.bat:


    del myapp.exe
    del myapp.exe
    del myapp.exe
    del myapp.exe
    del myapp.exe
    del myapp.exe
    del myapp.exe
    del myapp.exe
    del myapp.exe
    del myapp.exe

    @echo so many times, just to be shure that any timeout wouldn't stop the file remove

    ren newapp.exe myapp.exe
    myapp.exe

    //eof
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  16. #16
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    Or use the choice command

  17. #17
    Android OpenGL ES Guru Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,249
    I heard you can do anything to an EXE while it's running. Ever heard of EXE hijacking? Here's the source code to show you what I mean:

    http://www.planet-source-code.com/vb...44907&lngWId=1

  18. #18
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    Just for your info...you can create a loop that will try to delete the exe in the batch file, rather than putting the same line 10 times over. Even if you put it 10 times, it won't work on slow machines. Your best bet is a loop ==> goto loop
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  19. #19
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457
    Now where did I leave my Dos 6.2 manual. I had it here soemwehere .

    Thanks Guys.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  20. #20
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    How would you make this loop?

    Can you write the batch file code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width