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
Related
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
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
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
I'm running my program installer done with NSIS but the /D option seems not working (or better overridden inside).
Via command line I trigger:
installer.exe /S /D=C:\Users\Public\installDir
NSIS code is:
InstallDir "C:\Users\Public\${VERSIONSTR}"
Function xxxx
${If} $MultiUser.InstallMode == "AllUsers"
StrCpy $INSTDIR "C:\Users\Public\Dir1"
${EndIf}
IfSilent 0 +20
StrCpy $INSTDIR "C:\Userdata\Dir2"
FunctionEnd
The used installation folder is "C:\Users\Public\Dir2". Even if I comment the IfSilent block the installtion folder will be "C:\Users\Public\Dir1" but never the one passed via command line.
What's wrong in my script?
!include LogicLib.nsh
;InstallDir ; Do not use InstallDir at all so we can detect empty $InstDir
!define DEFDIR_MACHINE "$programfiles\foo"
!define DEFDIR_PERUSER "$localappdata\bar"
Function .onInit
${If} $InstDir == "" ; /D not used
${If} $MultiUser.InstallMode == "AllUsers"
StrCpy $InstDir "${DEFDIR_MACHINE}"
${Else}
StrCpy $InstDir "${DEFDIR_PERUSER}"
${EndIf}
${If} ${Silent}
StrCpy $InstDir "c:\CrazySilentOverride"
${EndIf}
${EndIf}
FunctionEnd
I have script watching file creation in a specific directory.
I'm using Register-ObjectEvent after creating a System.IO.FileSystemWatcher,
It works great, but if I set a break point in the -Action code block the IDE generates a:
WARNING: Breakpoint Line breakpoint on 'D:\My Stuff\Desktop\scripts\fileWatcher.ps1:15' will not be hit
this message happens right after I drop a file into the directory I'm watching and I can see my Write-Host printing out my message right after the above 'warning'.
Is this normal?
I need to add more code and could really use the debugger..
What can\should I do, so I can debug this code block?
$fsw = [System.IO.FileSystemWatcher] $path
Register-ObjectEvent -InputObject $fsw –EventName Created -SourceIdentifier DDFileCreated -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp" -fore green
Out-File -FilePath $logFile -Append -InputObject "The file '$name' was $changeType at $timeStamp"
}
If you trigger the event from a direct powershell command in the same ISE or console session, it actually works:
$path = (Resolve-Path '~\').Path
if(Test-Path "$path\newfile.txt"){ del "$path\newfile.txt" }
$fsw = [System.IO.FileSystemWatcher] $path
Register-ObjectEvent -InputObject $fsw –EventName Created -SourceIdentifier DDFileCreated -Action {
$name = $Event.SourceEventArgs.Name # put breakpoint here, via ISE or script
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp" -fore green
}
'foo' | out-file "$path\newfile.txt" # breakpoint hit
But if you simply hook up the event and wait for some external process to create a file, I see the issue you are hitting.
So if you can add some test code to directly trigger your event, go with that.
If not, read on...
It seems like you cannot enter the debugger while the shell or ISE is waiting for a new command, you can only enter while another command is executing.
Going with that theory, this is the workaround (works for me):
Set your breakpoint
Run your event subscription code
Run the command "Read-Host" in the ISE console window, or from the prompt in the shell
Wait until you know your event should have fired due to external process
Hit "enter" to allow Read-Host to complete
Viola, breakpoint hit!
The real key is to have a loop running so the script never exits. Then debugging and breakpoints work.
E.g.
# At the end of the script.
while ($true) {
Start-Sleep -Seconds 1
}
More detail is here.