Customize NSIS installer with Electron-builder - electron

I want to customize NSIS script - e.g. remove Finish Page and run app immediately after install (assisted installer is used).
I use modifying scrpt: include: build/installer.nsh.
It opens myApp after install but Finish page is still there.
!include MUI2.nsh
!macro customInstall
ExecWait '"$INSTDIR\myapp.exe" /sw'
!macroend
I mean I don't want to show the last page Completing myApp Setup as shown in gif.
Any help appreciated.

Finally I did it in build/installer.nsh:
!macro RunApp
${StdUtils.ExecShellAsUser} $0 "$launchLink" "open" ""
!macroend
!macro customInstall
!insertmacro RunApp
!insertmacro quitSuccess
!macroend

Related

electron-builder nsis run other executable during install

I'm trying to run a different executable during install of my app but I cannot find the right path to do it. The program is added with the following electron-builder config:
extraFiles:
- from: tools/tapinstall/${arch}/
to: resources/tapinstall/
filter:
- "**/*"
After installing my app I can see the files in the resources/tapinstall/ folder so it's being ported. Now, in my nsis installer.nsh I added an ExecWait directive to run an exe from that directory but it fails.
As a desperate measure I figured that prefixing everything with $INSTDIR was not the right move, maybe the path is not $INSTDIR and something else and I found 3 possible candidates:
$INSTDIR
$APPDATA
$BUILD_RESOURCES_DIR
I added this simple code to see which file gets created so I can figure out the right macro to use:
!macro customHeader
RequestExecutionLevel admin
!macroend
!macro customInstall
!system "echo 'as' > $INSTDIR/customInstall"
!system "echo 'bs' > $APPDATA/customInstall"
!system "echo 'cs' > $BUILD_RESOURCES_DIR/customInstall"
${ifNot} ${isUpdated}
!system "echo 'a' > $INSTDIR/customInstall"
!system "echo 'b' > $APPDATA/customInstall"
!system "echo 'c' > $BUILD_RESOURCES_DIR/customInstall"
${endIf}
!macroend
I then did a full search on my computer for a file called customInstall...nothing. What am I doing wrong?
!system (and all other ! instructions) are executed at compile-time inside makensis.exe. You cannot access variables/constants at compile time, only defines and environment variables.
!define foo "Hello"
!warning "${NSISDIR} & $%Temp% & ${foo}"
Var Bar
Section
StrCpy $Bar "World"
MessageBox mb_ok "$InstDir & $Bar"
SectionEnd

How do I run a .lua script in Notepad++?

I have a very basic .lua file saved in a folder, with just the code
print("Hello world")
I additionally have the standalone lua interpreter downloaded, but it is beyond me how to successfully run my code. I put all the files of the interpreter in the same folder but when I use F5 to run the program I see no text in the interpreter.
Run Notepad++.
On the menu select: Run -> Run.. (F5).
Insert: C:\path\to\lua.exe "$(FULL_CURRENT_PATH)"
Now you can run your scripts by pressing F5 on your keyboard.
Just do it with NppExec plugin:
SET interpreter = F:\lua\lua53.exe
SET exec = "$(interpreter)" "$(FULL_CURRENT_PATH)"
NPP_SAVE
$(exec)
if $(EXITCODE) != 0 goto exit
NPP_CONSOLE 0
NPP_RUN cmd /C "cmd /C $(exec) && pause"
:exit
KaMehHb's answer is correct, but one thing to add is either delete this line or change it to 1 if you want the console to stay up.
NPP_CONSOLE 0
to
NPP_CONSOLE 1

How to install application as windows service using NSIS script

How to install application as windows service using NSIS script?
I used this command in the script Exec '"sc.exe" but after installation i couldn't find any service in windows services related to it so help me thanks.
Maybe that the NSIS Simple Service plugin can help you. The syntax is as simple as
SimpleSC::InstallService "MyService" "My Service Display Name" "16" "2" "C:\MyPath\MyService.exe" "" "" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Here the example install the service as ServiceType own process + StartType automatic + NoDependencies + Logon as System Account.
Please refer to the accompanying help for the meaning of the magic numbers.
The wiki shows the 5 other methods to handle services with NSIS.
There are multiple plugins out there as stated on NSIS website
For me it seemed to be unnecessary complicated, so I ended up using sc tool directly. A command is quite simple:
!define appName "theApp.exe"
!define displayName "My Awesome Service"
!define serviceName "MyAwesomeService"
ExecWait 'sc create ${serviceName} error= "severe" displayname= "${displayName}" type= "own" start= "auto" binpath= "$INSTDIR\${appName}"'
A full list of sc create arguments available here
Below is the scripts which first stops service, uninstalls previous version, remove form registry and then installs fresh copy.
Section "Mobile Interface"
SimpleSC::StopService "MobileInterface" "1" "60"
SimpleSC::RemoveService "MobileInterface"
DeleteRegKey /ifempty HKLM "MobileInterface"
RMDIR /r "$INSTDIR\MobileInterface\"
SetOutPath "$INSTDIR\MobileInterface"
# define what to install and place it in the output path
File "D:\NCS.Sentinel\NCS.Sentinel.MobileWebSvc\bin\Release\"
SimpleSC::InstallService "MobileInterface" "MobileInterface" "16" "2" "$INSTDIR\MobileInterface\NCS.Sentinel.MobileWebSvc.exe" "" "" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
SimpleSC::StartService "MobileInterface" "" "100"
#WriteRegStr HKLM "D:\NCS.Sentinel\NCS.Sentinel.MobileWebSvc\bin\Release\NCS.Sentinel.MobileWebSvc.exe"
WriteUninstaller "$INSTDIR\Uninstall.exe"
; Store installation folder
;WriteRegStr HKCU "Software\Mobile Interface" "" $INSTDIR
SectionEnd

How to use an ampersand sign in a build event?

I'm trying to figure out how to call a PowerShell script with spaces in the filename as a Delphi build event.
From CMD I have to call powershell.exe -Command "& 'Filename With Spaces.ps1'" which works fine.
Delphi on the other hand doubles the ampersand sign and is trying to turn the command into two commands.
I have tried to set this as the build event:
powershell.exe -Command "& '$(PROJECTDIR)\Prebuild.ps1' $(PROJECTDIR)"
What gets executed by MSBuild is:
powershell.exe -Command "&& 'D:\SVN\AccuLib 3.0\VCLUI\Prebuild.ps1' D:\SVN\AccuLib 3.0\VCLUI"
So what does it take to call a ps1 file containing spaces from a Delphi build event?
Try the File parameter instead, it doesnt require an ampersand:
powershell.exe -File "Filename With Spaces.ps1"
To use an ampersand sign you can create an intermediate cmd script.
Delphi build event:
Prebuild.cmd "$(PROJECTDIR)"
Prebuild.cmd file:
powershell.exe -Command "& 'Filename With Spaces.ps1'"

Using updated NSIS path within the same installer

I am having a problem with updating the PATH variable. What I need to do is update the path (which works fine), and then immediately use the new version in the installer. This is not working.
Here is what I'm using to update the path:
!macro ADD_TO_PATH pathAdd
DetailPrint "Adding ${pathAdd} to the system PATH."
ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
WriteRegStr ${WriteEnvStr_RegKey} "PATH" "$1;${pathAdd}"
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
MessageBox MB_OK "Path: $1"
!macroend
And here is what I need to do with it:
Section "${PRODUCT_NAME}" SEC_R
DetailPrint 'Installing Python Dateutil...'
!insertmacro EXEC_OUT 'dtutil' 'easy_install python-dateutil' 'DateUtil' 'true'
SectionEnd
Where EXEC_OUT is the following:
; Silent execution of easy_install.
; abrt - is set to 'true', causes Abort on failure.
; name - user-friendly name to print
; package - unique name for labels
; what - full command to execute(ex: "easy_install packageXYZ")
!macro EXEC_OUT package what name abrt
MessageBox MB_OK "what: ${what}"
ExecWait "${what}" $0
${If} $0 == "0"
DetailPrint "${name} module installed successfully."
${Else}
DetailPrint "${name} failed to install: $0"
${If} ${abrt} == "true"
abort "An essential part of the installation, ${name}, failed to install. Aborting installation."
${EndIf}
${EndIf}
!macroend
Why is this not working? Is it not possible for the PATH to be updated before the application exits?
You need to set the environment variable for the running process as well.
http://nsis.sourceforge.net/Setting_Environment_Variables_to_Active_Installer_Process

Resources