Archive: Error message - copy file in use


Error message - copy file in use
Hey,

I have created a installer there are copying some files to a directory for a server there can be running. If the server is running i get the error message: "Error opening file for writing".

Is there a way that i can get a message in example: "The file xxxx is in use, please shutdown the server and run the installer again" then they can cancel shutdown the server and run the installation.

-Aaskilde


You cannot overwrite a file that is locked by another process (in your case, a server application). You must disable the process first. You can use for example the lockedlist plugin to check whether a file is locked. You can use this to (let the user) kill the application before you attempt to install.


Ya okay that could be an idea i need to find out if they may execute the process when the installer asks.

But what if i just want a messagebox up instead of the error messages there is when the file is in use? Then with that messagebox you can cancel the install.


You could try to delete the file, and if that sets the error flag you can be relatively sure that you won't be able to overwrite it either. Then you can throw your own messagebox error.

(Strictly speaking it is possible to have overwrite ('modify') privileges while not having 'delete' privileges. If NSIS first opens the file before attempting the overwrite, modify rights would be sufficient. I doubt that's how it's done, but I'm not sure.)


Another option is to replace on reboot:
http://nsis.sourceforge.net/Install_on_reboot

Stu


Okay the server that is using that file i need to overwrite is running on some of our users computers and if we can get passed it should not be restarted.

I was wondering if you could make something like this:

section "Messagebox1"

$INSTDIR

Messagebox MB_OK "The file xxxx is in use by the server. Please shut down the server and install again."
ok: Quit

sectionend

But is there maybe a command i can put in the section that checks if the file is in use?


As MSG said, try deleting the file. If that fails then you can show a message box. If you want to check earlier on (i.e. in .onInit) without deleting the file you can try appending to the file with FileOpen which should also fail.

Stu