Archive: Rename function and multiple hard drives


Rename function and multiple hard drives
I am having a problem with the Rename command in NSIS. Here is my code:


;-----------------------------------------
; CopyLockedFile
;-----------------------------------------
; Attempts to copy a file. If the file could not be copied, then
; the file is copied to a temporary location and copied to
; its proper directory after a reboot.
;-----------------------------------------
!macro CopyLockedFile FILE_NAME OUTPUT_PATH LOCAL_PATH
Push $R1

ClearErrors

; Try to copy the file.
SetOutPath ${OUTPUT_PATH}
SetOverwrite Try
File "${LOCAL_PATH}\${FILE_NAME}"
SetOverwrite On

; If we got an error copying, then the file was in use.
IfErrors FileNotCopied ExitOut

; The file could not be copied, most likely because it was in use.
FileNotCopied:
; Create a temporary file. The name of this file will be unique.
; The name will be stored in $R1.
GetTempFileName $R1

; Copy the output file over the temporary file we just created.
; For example, this would copy asteel2.exe to j2iofawer.atj (or some other unique temp file name).
File /oname=$R1 "${LOCAL_PATH}\${FILE_NAME}"

; Rename and copy the temp file ($R1) to the actual destination, renaming it to the proper name.
; If a reboot is required (probably always), set the reboot flag.
Rename /REBOOTOK $R1 "${OUTPUT_PATH}\${FILE_NAME}"

ExitOut:
Pop $R1
!macroend


And I call the function like so:


Section
!insertmacro CopyLockedFile qrpt60.bpl $INSTDIR\SYSTEM "${FilesDir}"
SectionEnd


Let's say I install on the C: drive on my Windows 2000 machine in some folder, launch my application (let's call it text.exe), then reinstall while my application is open. This is fine - test.exe is locked by the system because it is running, so based on the above code a temp file will be created and during the next reboot test.exe will be updated. This works great (except for the LFN/Win95 issue that I posted elsewhere).

Here is my problem. If I follow the same steps as above but do so on my D: drive, the files never get updated on reboot. What might cause this? How does Windows know to update files on reboot anyway (registry, ini file)?

Are they not updated on Windows 2000 or Windows 9x? On Windows 9x there is yet another problem that forces you to put both the source and the destination file on the same drive if replacing on reboot. To do so you can use GetTempFileName from the latest CVS version which takes another parameter which is the base directory. Use the same directory as the destination file and it should work.

If it happens on Windows 2000 then D: or the other drive are probably mapped network drive. If not, well... Respond and we'll see.


I am using MakeNSISW version 1.9, NSIS v2.03b. I haven't tried installing on Windows 95 with more than one hard drive. The problem above was on a Windows 2000 machine with a single hard drive partitioned into 2 drives - C: and D:. When installing to C: it works fine, but D: it doesn't. It's not a mapped network drive.

How does Windows know to update a file on reboot?


According to MSDN Windows NT keeps it in:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations

Your temporary directory is on C: right? What happens if you put the temporary file on D: too?