Archive: Overwrite a file in use


Overwrite a file in use
Hi

I was wondering if anybody knows how to force a file to be overwritten even if it is open? I know that there is a Win32 API function that can unlock files but I am not sure how to use it with NSIS. The file is on a mapped network drive.

Thanks


You could try the Network Share Management Functions.
Use NetFileEnum or NetFileGetInfo to get the ID of the open file, then call NetFileClose or NetFileClose2 to force the file to close.
CF


Hi

Can I be a real idiot and ask for the Nullsoft script code to do this? In my intaller I use file *.* to extract the files to the Temp folder. I then selectively copy files from the temp folder to the install path. Say I am trying to copy file test.dll and the copy is in use in the install path. How would I go about unlocking it?

And then how could I unlock a file if it is in a local folder and in use (e.g. would be c:\myfile.dll)

Thanks!


Look in the wiki for UpgradeDll. That page has a function to do just what you're looking for.

Don


I had looked at that. The files are on a server that can't be rebooted and the users often forget to close down the application before they leave. So we can't reboot the server, the files are locked and we need to overwrite them.


Maybe this would work: rename the dlls that are locked (I suggest that you use GetTempFileName and then delete the file that it creates or the rename will fail), and then copy your new dll into the directory. New applications should load with the new version of the dll and running applications will still use the old renamed dll.

You can clean up those old renamed Dll's by 'Delete /REBOOTOK $TempFileName' so that whenever the server finally gets rebooted they will be removed.

Don