Skip to content
⌘ NSIS Forum Archive

Self copy install ?

13 posts

SnipeGod#

Self copy install ?

Is there a way to make the install file copy itself after installation into the install dir ?
glory_man#

Function .onInstSuccess
CopyFiles /SILENT "$EXEDIR\Setup.exe" "$INSTDIR\Setup.exe"
FunctionEnd
glory_man#
System plugin can help you to detect filename

System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
After this call $R0 will be equal to full path of file (i.e. path and file-name). Parse this variable.
SnipeGod#
wow!
thanks 😁 but I'm new to this scripting system so I'm not sure how to combine those two scripts to make it work :P
glory_man#
I think this may be like this:

Function .onInstSuccess
System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
StrLen $0 $R0
Push $R0
Call GetParent
Pop $1
StrLen $1 $1
IntOp $0 $0 - $1
IntOp $0 $0 - 1
StrCpy $R1 $R0 "" "-$0"
CopyFiles /SILENT "$R0" "$INSTDIR\$R1"
FunctionEnd
Add:
Forgotten: GetParent function you can take from NSIS-docs - Appendix C - Get parent directory.
Afrow UK#
Rather than use GetParent to get the file name (for some reason) just use GetFileName:


Function .onInstSuccess
System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
Push $R0
Call GetFileName
Pop $R1
CopyFiles "$R0" "$INSTDIR\$R1"
FunctionEnd
Edit: Silent may not be wise if the installer is large.

-Stu
kichik#
Why use GetParent or GetFileName? CopyFiles works with full paths, it's even required:
Fully-qualified path names should always be used with this instruction. Using relative paths will have unpredictable results.
Afrow UK#
He needed the installer file to be copied to $INSTDIR.
GetFileName was used to get the installer file name from $R0.

-Stu