Archive: Improved UpgradeDLL macro


Improved UpgradeDLL macro
The improved UpgradeDLL macro can upgrades DLLs that are in use.

!macro UpgradeDLL
Exch $0
Push $1
Push $2
Push $3
Push $4
Push $5
ClearErrors
GetDLLVersionLocal ${DLL_NAME} $1 $2
GetDLLVersion $0 $3 $4
IfErrors upgrade_${DLL_NAME}
IntCmpU $1 $3 noupgrade_${DLL_NAME} noupgrade_${DLL_NAME} upgrade_${DLL_NAME}
IntCmpU $2 $4 noupgrade_${DLL_NAME} noupgrade_${DLL_NAME}
upgrade_${DLL_NAME}:
GetTempFileName $5
File /oname=$5 ${DLL_NAME}
UnRegDLL $0
delete /REBOOTOK $0
rename /REBOOTOK $5 $0
IfRebootFlag regreboot regnoreboot
regreboot:
WriteRegStr HKLM Software\Microsoft\Windows\CurrentVersion\RunOnce $0 "$SYSDIR\regsvr32 /s $0"
goto regrebootfinish
regnoreboot:
RegDLL $0
regrebootfinish:
noupgrade_${DLL_NAME}:
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
!undef DLL_NAME
!macroend


Be aware theres a bug in this macro.

You will never execute
IntCmpU $2 $4 noupgrade_${DLL_NAME}

Se my fix elsewhere in the forum


Beyond the issue reported by B. Jensen there is an additional bug in your code for Windows 9X users (not sure about NT/2000/XP). The code:

delete /REBOOTOK $0
rename /REBOOTOK $5 $0

does not produce desired results when the files are in use and need to be manipulated during reboot. On Win 9X systems NSIS uses the WININIT.INI file to do this. In the above sequence, somehow (NSIS bug?) the rename code gets put in BEFORE the delete code and the DLL is therefore missing when the boot is complete. To fix, just skip the delete command and let the rename take care of it.

Regards,

mmullikin


UpgradeDLL on Win9X
As mmullikin said, there is a bug in the following code on win9x

delete /REBOOTOK $0
rename /REBOOTOK $5 $0

However, mmullikin's suggestion that only using the second line doesn't work on my test either.

Could anyone provide me the UpgradeDLL which can work on win9x?
I mean it can upgrade dll being used on win9x.


What about the following workaround?
Detect the Windows version in the script and if it's Win9x use
rename /REBOOTOK $5 $0
delete /REBOOTOK $0
else use
delete /REBOOTOK $0
rename /REBOOTOK $5 $0

However, I've not tesed it!! Use at own risk.