- NSIS Discussion
- How to detect a file is locked when deleting a file
Archive: How to detect a file is locked when deleting a file
JamesKiller
30th March 2007 19:28 UTC
How to detect a file is locked when deleting a file
Hi All,
When I try to delete a file during the uninstallation, just like some .dll, .exe files. If they are still in use or rights issues, I couldn't delete them.
When trying to overwrite the files, i couldn't overwrite them?
how can I detect them? and how to solve?
Any thoughts?
James
kichik
30th March 2007 20:09 UTC
Use the Library macros.
http://nsis.sourceforge.net/Docs/AppendixB.html
JamesKiller
30th March 2007 22:13 UTC
coulde you give me an example????
Thank you.
kichik
30th March 2007 22:17 UTC
That page contains examples.
JamesKiller
30th March 2007 22:42 UTC
IfFileExists "$INSTDIR\MyApp.exe" 0 new_installation ;Replace MyApp.exe with your application filename
StrCpy $ALREADY_INSTALLED 1
new_installation:
!insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_NOTPROTECTED dllname.dll $SYSDIR\dllname.dll $SYSDIR
hmmmm
if i have 20 files, i should write them like above 20 times?
kichik
30th March 2007 22:47 UTC
If your DLL files are not shared, there is no need for anything but the InstallLib macro. Instead of $ALREADY_INSTALLED, use NOTSHARED. If they are shared, do the test just once, keep the value in $ALREADY_INSTALLED and just add more InstallLib lines.
JamesKiller
30th March 2007 23:18 UTC
If a file is locked, how can i get the error message?
If the istaller has error, how can I display error message, I mean NSIS error message..
Iferrors 0
MessageBox MB_OK error_message(NSIS message,not my own message)
JamesKiller
30th March 2007 23:21 UTC
-------------------
on the link you gave to me, it says it can:
***
Windows File Protection checks
***
How to checks, if file protected, how can show message?
kichik
30th March 2007 23:21 UTC
If a file is locked the error flag will be set and, if you've enabled reboot, the reboot flag will also be set. There's no message, just a state of failure to delete or replace the file.
kichik
30th March 2007 23:22 UTC
Files installed by your application are most probably not protected. Only system files are protected by WFP.
JamesKiller
30th March 2007 23:47 UTC
when I run in windows mode (not silent mode, it will show the file is in use. However, run in silent mode . it won't show the error message.....
I am expecting the error message in the silent mode.
kichik
30th March 2007 23:59 UTC
What error message? The Library macros show no error message. if you're talking about the normal error message for when a file can't be overwritten, then on silent mode it takes the default action of skipping the file or aborting if AllowSkipFiles is set to off.
JamesKiller
31st March 2007 00:10 UTC
Yeah. You are right.
The error message is like " Error opening file for writing:
c:\myapp.dll ....."
Can I get this error message in silent mode. If I can't, can I set an error flag for this copying file error?
Thank you for your help.
JamesKiller
31st March 2007 00:12 UTC
Or before getting this error message, can I pop up an message like "myApp.dll is in use, can't copy this file!", then I can exit the installer.
kichik
31st March 2007 10:01 UTC
The error flag is already set when this message appears. You can try deleting the file and checking the error flag to avoid this message on non-silent mode.
JamesKiller
31st March 2007 18:46 UTC
How can set the error flag? which error flag?
Thank you....
Brummelchen
31st March 2007 19:13 UTC
clearerrors
delete "file.bla"
iferrors error_routine
;no errors
;error
error_routine:
Red Wine
31st March 2007 19:23 UTC
Regarding to the uninstaller, if you're using MUI, you may add the MUI_UNPAGE_FINISH and for every suspected delete instruction, add the switch /REBOOTOK.
If file(s) failed to delete, the finish page should appear with reboot checkboxes.
Without MUI_UNPAGE_FINISH you may check in function un.onUninstSuccess the reboot flag (IfRebootFlag), and if is set pop up a message about.
Brummelchen
31st March 2007 21:24 UTC
From experience - reboots are not necessary in most cases.
it only need some brain and an idea to replace/rename
files. the reboot only do the cleanup.
- push the filename
- call replacing routine:
-- delete file -> on success return
-- unregister file
-- delete file -> on success return
-- rename file
-- delete renamed file -> on success return
-- delete renamed file on reboot
-- return
- copy new file
- reset reboot flag (we dont really need it)
normally user dont work on windows system files so that a reboot is a must
JamesKiller
1st April 2007 03:56 UTC
Thank you all for help. I will test it up. Hopefully, i can fix the bug we have.
onad
3rd April 2007 10:30 UTC
Wrote: "Can I get this error message in silent mode."??
"silent" = no UI interaction nothing displayed only error(result codes)
"un-attended"= Display of progress but no UI interaction
"regular"= UI interaction and Display of progress