Nsis7z not getting it. - nsis

Do i am missing something here. I found Nsis7z and found the example.
File "ArchiveName.7z"
Nsis7z::Extract "ArchiveName.7z"
Delete "$OUTDIR\ArchiveName.7z"
So I tool that and created:
Section
# Init temporary folder $PLUGINSDIR
InitPluginsDir
# Include 7-zip archive
SetOutPath "$PLUGINSDIR"
ReserveFile "F:\test.7z"
# Extract archive
Nsis7z::Extract "$PLUGINSDIR\test.7z"
Delete "$PLUGINSDIR\test.7z"
SectionEnd
I see the temp folder get created, but nothing ever extracts to the temp folder except the nsis7z.dll.
what am I missing. It looks so basic.

Section
# Init temporary folder $PLUGINSDIR
InitPluginsDir
# Include 7-zip archive
SetOutPath "$PLUGINSDIR"
ReserveFile D:\test.7z
File Test.7z
# Extract archive
Nsis7z::ExtractWithCallback "$PLUGINSDIR\test.7z"
Delete "$PLUGINSDIR\test.7z"
SectionEnd
You forget to add File Test.7z

Related

How to delete the startup file itself test.exe?

After running the .exe file, I need to delete the file so that it no longer exists.
I have a script that I create a file to run, but how to delete it after launch?
Outfile test.exe
Requestexecutionlevel user
Setcompressor LZMA
Page instfiles
Section
;Not a good idea to hardcode the destination like this,
;normally you would use a directory page so the user can choose
SetOutPath "c:\SaveToThisFolder"
;Take thefile.txt from the system you compile on and output it on the end users system
;into the directory specified by the SetOutPath call
File "thefile.txt"
Sectionend
How to delete file test.exe after run?
It is hard for a Windows process to delete itself and NSIS does not really support it but you can try the SelfDel plug-in

How to move a subdirectory with its contents to another directory with NSIS

this is the first time I work with NSIS, I want to edit an script NSIS to allow me:
If first instalation -> create the directory "Affaires" in the location "C:\Users\ali.ait-mouhoub.ext\AppData".
If it is an update (So the directory "Affaires" it already exists in "C:\N.O.E") -> move the directory "Affaires" with its contents to "C:\Users\ali.ait-mouhoub.ext\AppData".
The current script creates the directory "Affaires" in "C:\N.O.E".
Can you please help me modify my script to meet my needs?
If the both the new and old locations are on the same volume then you can use Rename:
Section
Rename "$InstDir\Stuff" "$InstDir\OldStuff"
SectionEnd
If the new location might be on a different volume then you have to copy+delete:
!include LogicLib.nsh
Section
ClearErrors
CopyFiles /Silent "$InstDir\Stuff" "x:\Backup"
${If} ${Errors}
MessageBox MB_ICONSTOP "Unable to move!"
${Else}
RMDir /R "$InstDir\Stuff"
${EndIf}
SectionEnd

How do I execute the app right after installation ... with arguments?

My installation EXE should unzip itself in a temp folder, then execute an app therein (with passing args), return and delete the temp folder again.
How do I write the nsi script?
It sounds to me like you are trying to create a portable application. Portable applications are always better when the original author adds support for it because it can handle registry and other configuration files correctly.
If you still want to create a launcher application you can do something like this:
OutFile "MyLauncher.exe"
RequestExecutionLevel User
SilentInstall Silent
SetCompressor LZMA
!include FileFunc.nsh
!insertmacro GetParameters
Section
${GetParameters} $1
InitPluginsDir
SetOutPath $PluginsDir
File "c:\myfiles\MyApp.exe"
File /r "c:\myfiles\otherfiles\*.*" ; If you need to include other files required by the application
ExecWait '"$PluginsDir\MyApp.exe" /param1 "pa ra m2" /param3 $1' $0 ; $1 contains the parameters passed to your launcher, remove it if you don't want to pass those arguments
SetErrorLevel $0
SetOutPath $Temp ; Don't lock $PluginsDir so it can be deleted automatically by the installer
SectionEnd
Answering my own question.
The required nsi script skeleton should look like this:
# The name of the installer (arbitrary)
Name "hello"
# The name of the installation file
OutFile "hello.exe"
# where put the installation - other options would be $TEMP, etc.
InstallDir $DESKTOP
RequestExecutionLevel user # no Windows UAC popup please!
SilentInstall silent # completely silent install
SetCompressor /SOLID /FINAL lzma # max compression for inst. file
# The stuff to install
Section ""
SetOutPath $INSTDIR # where to install (overwritable by user!)
File /r D:\...\... # where the install material lives
SectionEnd
# this function auto-runs after installation is fine
Function .onInstSuccess
# parameter are passed through via $CMDLINE
ExecWait '"$OUTDIR\hello.dist\hello.exe" $CMDLINE'
RMDir /r "$OUTDIR\hello.dist" # remove install folder again
FunctionEnd

NSIS - Adding other type of files

I have a NSIS generated-installer, however, I would like to add other files to the installer at compile time. For example, I want to add a batch file to the installer, so when the .exe file is ran, I can call that batch file within the .exe without needing to copy the actual batch file to the output location. This means the batch file will actually exist within the installer.
I hope this makes sense and thanks.
A batch file has to be extracted somewhere before it can be executed. $PluginsDir is a good choice because it is deleted when the installer ends.
Section
SetOutPath $Instdir
File myfiles\*
InitPluginsDir
SetOutPath $PluginsDir
File file.bat
nsExec::Exec '"cmd.exe" /c if 1==1 "$PluginsDir\file.bat"'
Pop $0 ; Exit code
SetOutPath $Temp ; Don't hold lock on pluginsdir
SectionEnd

How to pack files into exe and extract it at specified folder with NSIS?

I wrote a NSIS-script that creates an exe wich creates a new folder and copies files into the folder. Is there a way to include the files into the exe?
Name "First Installer"
OutFile "firstinstaller.exe"
InstallDir C:\dev\NSIS\Scripts\FirstInstaller
Section "move test.exe"
CreateDirectory $INSTDIR\test
SetOutPath $INSTDIR\test
CopyFiles $EXEDIR\test.txt $EXEDIR\test
SectionEnd
I now want to include the test.txt into the exe! Now you only have to start the exe and the test.txt is extracted from the exe into the created folder!
Name "First Installer"
OutFile "firstinstaller.exe"
InstallDir D:\dev\FirstInstaller
Section "move test.exe"
;CreateDirectory $INSTDIR\test
SetOutPath $INSTDIR\test ; extract exe content at this path, you can also specify other path
File /r "D:\dev\test.txt" ;used to include file in exe
SectionEnd

Resources