Old 23rd June 2008, 18:18   #1
richiebabes
Junior Member
 
Join Date: Jun 2008
Posts: 27
How to handle replacing files which are in use?

I created an NSIS install script that works unless a certain application is running which is part of the install. What is the best way to handle this?

I.e. let's say myexecutable.exe is in the list of files I want to install but when the user installs they have an older version running and myexecutable.exe is running.
richiebabes is offline   Reply With Quote
Old 23rd June 2008, 19:38   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
This is a macro I use to replace on reboot:
code:
!macro InstallOnReboot Source Destination
SetFileAttributes `${Destination}` NORMAL
File `/oname=${Destination}.new` `${Source}`
Delete /rebootok `${Destination}`
Rename /rebootok `${Destination}.new` `${Destination}`
!macroend


Usage:
code:
!insertmacro InstallOnReboot localfile.exe $SYSDIR\outfile.exe

The SetFileAttributes fixes a problem we found with files set to hidden+system (they were not always replaced).

Stu
Afrow UK is offline   Reply With Quote
Old 23rd June 2008, 19:52   #3
richiebabes
Junior Member
 
Join Date: Jun 2008
Posts: 27
OK, I figured out how to use this and it works... but the only problem is that it requires a reboot. Is there no way we can ask the user to nicely close down the application before proceeding with the install?

Last edited by richiebabes; 23rd June 2008 at 20:35.
richiebabes is offline   Reply With Quote
Old 23rd June 2008, 20:40   #4
richiebabes
Junior Member
 
Join Date: Jun 2008
Posts: 27
Like you know, a handy window saying "The following applications need to be closed down before installation can continue. Please close them and click Retry to continue, or you will be sent to the fires of hell for the weekend".
richiebabes is offline   Reply With Quote
Old 23rd June 2008, 20:47   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Sure, http://nsis.sf.net/LockedList_plug-in
You can use the AddModule function and give it the path to your application.

Stu
Afrow UK is offline   Reply With Quote
Old 23rd June 2008, 21:17   #6
richiebabes
Junior Member
 
Join Date: Jun 2008
Posts: 27
Awesome, thanks!
richiebabes is offline   Reply With Quote
Old 23rd June 2008, 21:57   #7
richiebabes
Junior Member
 
Join Date: Jun 2008
Posts: 27
Is it possible to only show the locked files page if there are actually files to be closed? If there are none I'd really like to just skip past it...
richiebabes is offline   Reply With Quote
Old 24th June 2008, 09:11   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
This would be a good addition. I'll add that option when I am next free (may be at the weekend).

Stu
Afrow UK is offline   Reply With Quote
Old 25th June 2008, 20:55   #9
richiebabes
Junior Member
 
Join Date: Jun 2008
Posts: 27
Good stuff. If I have any spare time (rofl) I can look into it too now I am getting the hang of this NSIS stuff.

Just want to say, after being plagued with using InstallShield the last couple of years, NSIS is a wonderful breath of fresh air!
richiebabes is offline   Reply With Quote
Old 20th January 2009, 17:22   #10
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
coming from...
http://forums.winamp.com/showthread....42#post2476542
( WINAMP.COM | Forums > Developer Center > NSIS Discussion > How do we overwrite a running file )

Quote:
Originally posted by Afrow UK
This is a macro I use to replace on reboot:
Could that easily be adapted to try the File method first, then check for the Error flag, and only use the .new-extraction/delete/rename on reboot -if- the File method failed?
I think that in the end, the result would be the same, but the number of file interactions would presumably go down? Any caveats with that thought?
Animaether is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump