-
Implementing auto update
Hello all,
I'm trying to figure out how to do this... This is what I've come up with:
- Check for a new version on the net
- If there is a newer version of the executable (or any component), download it
- replace the needed files
Now it's the last part that's being kinda hard... How do I replace for example the executable? (AFAIK it's locked) I found some things, like renaming the file but that wouldn't always work and sometimes involve a reboot, wich I want to avoid. To avoid replacing locked files, I could use a launcher program:
- Launcher updates the main program, then executes it
- Main program updates the launcher
That seems ok to me, BUT I need to be sure that the main program can only be launched by the launcher. How do I do such a thing? Any tips? Thanks in advance,
David Jennes
-
or, you could make the program that downloads the update a different program. example:
example.exe connects to server and detects an update
example.exe opens update.exe
update.exe closes example.exe and makes sure it's closed before it updates
update.exe downloads the new example.exe and replaces the old one
-
checked the programming faq. Is spwan() with P_OVERLAY what I need? aka, with that, am I sure the old program is closed?
-
HWND FindWindow(
LPCTSTR lpClassName, // pointer to class name
LPCTSTR lpWindowName // pointer to window name
);
details All programs started in windows have a window <duh> :)
This API call finds the window handle for a running process.
-----------------------------------------------------------------------------
DWORD GetWindowThreadProcessId(
HWND hWnd, // handle to window
LPDWORD lpdwProcessId // address of variable for process identifier
);
details We can't do much with only the Window handle, we need to have
the process id to be able to get the process handle.
-----------------------------------------------------------------------------
HANDLE OpenProcess(
DWORD dwDesiredAccess, // access flag
BOOL bInheritHandle, // handle inheritance flag
DWORD dwProcessId // process identifier
);
details And you guessed, this one gets the process handle based on
the process ID.
-----------------------------------------------------------------------------
UINT SetTimer(
HWND hwnd, // handle of window for timer messages
UINT idTimer, // timer identifier
UINT uTimeout, // time-out value
TIMERPROC tmprc // address of timer procedure
);
details This API is used to generate a timer message at a certain interval.
We'll use it to check whether or not keys have been pressed and
if so to read or write values to the game's memory.
-----------------------------------------------------------------------------
SHORT GetAsyncKeyState(
int vKey // virtual-key code
);
details This API checks to see if a key has been pressed since last call to
the API. We need to call this one over and over again (see SetTimer)
-----------------------------------------------------------------------------
BOOL WriteProcessMemory(
HANDLE hProcess, // handle of process whose memory is written to
LPVOID lpBaseAddress, // address to start writing to
LPVOID lpBuffer, // address of buffer to write data to
DWORD cbWrite, // number of bytes to write
LPDWORD lpNumberOfBytesWritten // actual number of bytes written
);
details I'm not religious, but we really have to thank God to have Billy-boy
include this API into Windows. This is the heart of every trainer.
It can write values to memory.
-----------------------------------------------------------------------------
BOOL ReadProcessMemory(
HANDLE hProcess, // handle of process whose memory is read
LPVOID lpBaseAddress, // address to start reading
LPVOID lpBuffer, // address of buffer to read data to
DWORD cbRead, // number of bytes to read
LPDWORD lpNumberOfBytesWritten // actual number of bytes read
);
details And of course, this is WriteProcessMemory's twin. It can read
values from memory.
-----------------------------------------------------------------------------
VOID ExitProcess(
UINT uExitCode // exit code for all threads
);
details Windows closes all handles and cleans just about everything, but
its a good programming practise to close it yourself. This one
closes a process.
Remembered seeing this at a game hacking site, should be useful to ya.
-
I'm not really getting the purpose off all those calls...
Are you trying to tell me this?
- find the process
- write the update to the memory of that process
(not getting the purpose of those read keys / timer api's)
Isn't that spawn() with that parameter I said (wich unloads the main program from memory and opens the child process to replace the main program) enough to do this?
btw, I'm programming a command line tool, so those things with get window ... isn't of any use to me :P