Replace File On Reboot: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Created page with "== The Script == <highlight-nsis> !define PRODUCT_CODE "MyProductCode" RequestExecutionLevel admin ShowInstDetails show ; The name of the installer Name "ReplaceOnReboot" ; ...")
 
m (→‎Description: Grammar.)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{PageAuthor|Shane}}
== Description ==
Replace an existing file on reboot (for replacing files in-use, etc.).
== The Script ==
== The Script ==
<highlight-nsis>
<highlight-nsis>

Latest revision as of 20:31, 6 May 2013

Author: Shane (talk, contrib)


Description

Replace an existing file on reboot (for replacing files in-use, etc.).

The Script

!define PRODUCT_CODE "MyProductCode"
 
RequestExecutionLevel admin
ShowInstDetails show 
 
; The name of the installer
Name "ReplaceOnReboot"
 
; The file to write
OutFile "ReplaceOnReboot.exe"
 
; Get the existing product installation directory - use that for the INSTDIR value
InstallDirRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_CODE}" "InstallLocation"
 
 
Section "" ;No components page, name is not important
	StrCmp $INSTDIR "" 0 +2 ; If the INSTDIR is empty, we need to abort
	Abort 
 
	;Stage the files in the Windows\Temp directory until the next reboot
	;then call MoveFileEx to move them after the next reboot
	CreateDirectory "$WINDIR\Temp\${PRODUCT_CODE}" 
	SetOutPath "$WINDIR\Temp\${PRODUCT_CODE}"
 
	File "test.dll"
 
	;Call MoveFileEx on each file above (Params: <source>, <destination>, 4) 5 == Move on Reboot && Replace Existing
	System::Call "kernel32::MoveFileEx(t '$WINDIR\Temp\${PRODUCT_CODE}\test.dll', t '$INSTDIR\test.dll', i 5)"
 
SectionEnd ; end the section