Install on reboot

From NSIS Wiki
Jump to navigationJump to search
Author: Afrow UK (talk, contrib)


Description

This macro can be used to install a file on reboot if the file is in use at time of installation.

Macro(s)

!macro InstallOnReboot Source Destination
  SetFileAttributes `${Destination}` NORMAL
  File `/oname=${Destination}.new` `${Source}`
  Delete /rebootok `${Destination}`
  Rename /rebootok `${Destination}.new` `${Destination}`
!macroend
!define InstallOnReboot `!insertmacro InstallOnReboot`
 
!macro DeleteOnReboot Path
  IfFileExists `${Path}` 0 +3
    SetFileAttributes `${Path}` NORMAL
    Delete /rebootok `${Path}`
!macroend
!define DeleteOnReboot `!insertmacro DeleteOnReboot`

Note the resetting of a files' attributes. Windows can fail to perform an operation if a file has HIDDEN+SYSTEM set.

Usage

${InstallOnReboot} some_file.exe $INSTDIR\some_locked_file.exe
${DeleteOnReboot} $INSTDIR\some_locked_file.exe

Stu