[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to get started

Robert Collins wrote:
On Mon, 2003-12-01 at 12:04, Satadru Pramanik wrote:

Windows has been moving further and further away from a paradigm of requiring reboots to replace files. Whatever glue is written to get around the problem of not being able to replace in use files, please consider the use of functionality such as qchain in windows, which lets you schedule several reboot requiring updates for just one reboot cycle.


Microsoft have got better at dynamically unloading and reloading
modules, thus working around the issue...but the underlying problem -
that a open file/directory cannot be replaced
hasn't changed at all.

I've done some googleing and it looks like it is possible to rename a file that's in use (from the command-line). Of course, there's no way to find out if this works _all_ the time, but according to http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=9486169wnr%40ttelmah.demon.co.uk it should work:

"In article: <36344dc7.0@>  frode.gill@agresso.no (Frode
Gill) writes:
> In article <390103591wnr@ttelmah.demon.co.uk>, Roger@ttelmah.demon.co.uk wrote:
> >> How can I copy a dll file to the system32 directory if the file  is
> >> being used by Windows?
> >
> >The normal 'proceedure' is:-
> >rename the.dll the.old
>  ^^^^^^
> And this is not possible when the .dll is in use by windows...
> Another way of doing it, is to put the new <file>.dll in the  directory
> as <file>.tmp, and have it renamed to .dll during startup. There is  a
> way to set this in the registry - not sure how to do it though  :-/

Since when?. You can rename a DLL in use, you just cannot move it.
This is the proceedure used by most standard 'updates' (including
those from MS). You _must_ have administrator priviledges. The code
'using' the DLL will carry on happily using the 'renamed' one, until
you re-boot."

If he's correct that MS also uses this method, it shouldn't be too difficult to just rename the file inuse and delete it later if it's not in use anymore.

There's also some articles:



According to these articles there are two utilities that might be used to replace system files that are in use: inuse.exe and mv.exe. (It seems that inuse.exe is newer.)

These make use of a registry key that can be delay file operations until the next reboot: "this executable actually does an edit to the registry to perform a "PendingFileRenameOperations" on the next reboot."

So, the simplest strategy would  be something like:


void replaceFile( const char* src, const char* dest )
    const char* destOld = getOldFilename(dest); // Unique filename
    if ( rename( dest, destOld )

        if ( !inuse(destOld) )


    cerr << "WARNING: could not rename " << dest;
    cerr << ". Replacement of " << dest;
    cerr << " is delayed until reboot." << endl;

    const char* tempfilenm = getTempfileName(dest);
    copy( src, tempfilenm );


We can use the "PendingFileRenameOperations" registry key both for deleting the old files and for replacing those files that couldn't be renamed in case there would be files that couldn't be renamed.

-- Arend --

Reply to: