C++ Win32 Close All Programs Using The .exe File

Started by
9 comments, last by BennettSteele 12 years, 1 month ago
I just finnished coding a installer/updater for my game. I have 1 problem though: i want it to install the game.exe if its not there and re-write it if out-dated. you can run the updater.exe to install the game. when you launch the game.exe, it runs the updater.exe to check for updates... but i cant update the game.exe if its open. what should i do to close all instances of the game.exe file so i can write to it?
Advertisement
Make the updater be the program the player launches and not the game. The updater does any necessary updates and then launches the game.

Note that running a program will keep a file handle open to the exe, which will be closed when the program exits.
but i have the version stored in the game.exe (define VERSION "0.01") and i dont want the user to be able to change that.
How do you think doing it the other way round will prevent that?

You can't stop users from changing files on their own PC.
Good point... is there a way to run a .exe and exit the program that called to run that file?
Google found this when searching "windows end process c++".
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
I shouldnt have posted that, i should of taken responsibility (which i did right after posting) and find out for myself. i think i found a way... i will have to do more testing...

it goes like this:

CreateThread(Updater);
exit();

it works right now, i will need to mess around with it more to make it work.
You probably should be creating processes, not threads.

I shouldnt have posted that, i should of taken responsibility (which i did right after posting) and find out for myself. i think i found a way... i will have to do more testing...

it goes like this:

CreateThread(Updater);
exit();

it works right now, i will need to mess around with it more to make it work.


Really. You're creating a worker thread and then exit right away? I'd expect that to end the entire process immediately, including your freshly started worker thread.

but i have the version stored in the game.exe (define VERSION "0.01") and i dont want the user to be able to change that.


Version numbers aren't really useful for updating. File should be updatable even if it's corrupted or missing.

Do a SHA or similar checksum. Post that to server. If server recognizes the hash, send the upgrade path (install 0.02, then 0.02b, then 0.03...).

If server doesn't recognize the hash, assume the installation has been corrupted and send full install of latest version.

Upgrades like that can be easily hosted in web-based CDN server where you just lookup the hash (patch.com/title/841fae63ebbc or similar), which download the upgrade from that version to next one. There's also the patch.com/title/latest, which obviously returns latest fill install.

This topic is closed to new replies.

Advertisement