Implementing auto update

This is a discussion on Implementing auto update within the C++ Programming forums, part of the General Programming Boards category; Hello all, I'm trying to figure out how to do this... This is what I've come up with: Check for ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Location
    Genk, Belgium
    Posts
    8

    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

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    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
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    Registered User
    Join Date
    Oct 2005
    Location
    Genk, Belgium
    Posts
    8
    checked the programming faq. Is spwan() with P_OVERLAY what I need? aka, with that, am I sure the old program is closed?
    Last edited by djbe; 10-26-2005 at 09:09 AM.

  4. #4
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    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.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  5. #5
    Registered User
    Join Date
    Oct 2005
    Location
    Genk, Belgium
    Posts
    8
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polymorphism; Update functions and accessibility
    By CaptainMaxxPow in forum C# Programming
    Replies: 2
    Last Post: 04-23-2009, 08:48 AM
  2. SQLite not performing update
    By OnionKnight in forum C Programming
    Replies: 0
    Last Post: 01-21-2009, 03:21 PM
  3. July 9 2008 MS XP Update
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 07-18-2008, 05:14 AM
  4. emailing - auto update of address book from .csv
    By henryzhang in forum C++ Programming
    Replies: 2
    Last Post: 04-04-2006, 06:34 AM
  5. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21