Aaskilde
19th October 2011 10:09 UTC
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
MSG
19th October 2011 10:13 UTC
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.
Aaskilde
19th October 2011 11:02 UTC
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.
MSG
19th October 2011 11:33 UTC
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.)
Afrow UK
19th October 2011 11:42 UTC
Another option is to replace on reboot:
http://nsis.sourceforge.net/Install_on_reboot
Stu
Aaskilde
20th October 2011 08:10 UTC
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?
Afrow UK
20th October 2011 10:32 UTC
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