specificing destination directory in nsis (zipped installation) - nsis

I'm new to NSIS and creating one installer for our project.
The requirement is: there are 1 folder and 2 exes needs to be installed as part installation. These exes are created using nsis (Y.exe, Z.exe). These exes should be installed in different destination folder. I've tried this two approches:
Approach 1:
in script these variables assigned
RUN_Y C:\Installer\misc_exe\y.exe
RUN_Z C:\Installer\misc_exe\y.exe
Y_INSTALL_DIR INSTDIR\Y\ # INSTDIR is specified by user during folder installation
Z_INSTALL_DIR INSTDIR\Z\ # INSTDIR is specified by user during folder installation
# calling this at the time exe installation
setoutpath SetOutpath "${Y_INSTALL_DIR}"
ExecWait '"${RUN_Y}"'
setoutpath SetOutpath "${Z_INSTALL_DIR}"
ExecWait '"${RUN_Z}"'
Problem is, the destination folder is always coming as C:\Installer\misc_exe\ , whereas it should be C:\Y\. How can I fix it?
Approach 2:
While creating the zipped folder to exe, I gave destination folder as $INSTDIR/Y/ and $INSTDIR/Z/, and I think, this $INSTDIR is taken from the 1st folder installation. But, its not working that way.
can anyone help with me with how can I do specific folder installation?
Thanks in advance.

I am not sure what are you trying to do but to set target directory use
InstallDir "C:\Y\"
command.

Related

NSIS Installer Run Batch File

Trying to run a batch file at the end of an installation, everything works great except this file won't run.
section "Startup"
Exec '"$0" /C "C:\Program Files\placeholder\startup\startup.bat"'
sectionEnd
Everything gets deposited in the right spot, using absolute pathing to call this. I asked for administrator privileges at the start,
RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on)
Just copying from the example NSIS installer provided here
The file is there so I must be making a mistake with the file path or missing some parameter. Been trying a lot of permutations like nsExec but not sure my mistake. Hopefully this is a simple mistake and will aid others in the same boat at some time.
Without more information I would guess that this is a 64-bit Windows machine and filesystem redirection is causing your 32-bit installer to access the wrong program files directory.
The code you posted is also problematic because we don't know what $0 is. I assume you failed to post the code where it expands %comspec%. To rule out this, replace $0 with $sysdir\cmd.exe.
Ideally your installer should extract the batch file to the destination directory:
Section
SetOutPath $InstDir
File batch.bat
ExecWait '"$sysdir\cmd.exe" /C if 1==1 "$InstDir\batch.bat"'
SectionEnd
If you must access the 64-bit folder you can disable the redirection but this is not recommended:
!include x64.nsh
Section
${DisableX64FSRedirection}
ExecWait ... $ProgramFiles64\...
${EnableX64FSRedirection}
SectionEnd
I think that you should give us more information to solve this problem.
Based on current information, I guess there are two reasons:
"C:\Program Files" is a path for 64-bit programs, but NSIS installer is a 32-bit program, so this path will be redirected to "C:\Program Files (x86)". You can use the solution from Anders to solve it.
Your batch file may contains relative paths. When you run your batch file from the NSIS installer, your working directory is not as same as your batch file. Due to this, some command cannot run correctly. You can use %~dp0 to solve it.

How to add directory and sub directories in installer package

I have many files and folders to be added to my installation package. I tried command
File /nonfatal /a /r "C:\Users\test\hdp*"
and
File /nonfatal /a /r "C:\Users\test\hdp\"
but it didn't create the output file(.exe). I also tried with zip file (means created zip file of hdp folder) and add it into package but the same issue i am facing with zip file also.
hdp folder size is 250MB only.
In documentation also no option is mentioned to add folder. Can someone suggest how to add these folder and subfolders to the package?
You should start with Example1.nsi and understand all of its instructions before trying to write a real installer.
OutFile "myinstaller.exe" ; Name of generated installer .exe
InstallDir "$Desktop\MyApp" ; Change this
Page Directory
Page InstFiles
Section
SetOutPath $InstDir
File /r "c:\users\test\myfilestoinstall\*.*" ; Change this
SectionEnd

NSIS set temp folder name at run-time

I am currently extracting some files needed by the installer in a folder placed in the Windows temp directory. The way I have set it now is that that folder has a unique name based on the product name as well as the date.
The problem is that the whole folder name variable is set at installer build time and not when the installer is run, which means that I don't have a new temporary folder each time the same installer is run.
The code I'm using to create the folder is:
; Support folder
; this folder will contain temporary files visibible only for the lifetime of the installation
!define /date SUPPORTDIR "$TEMP\${PRODUCT_NAME}_%y%m%d%H%M%S"
var InitSupportDirDone
function InitSupportDir
${if} $InitSupportDirDone != 1
SetOutPath "${SUPPORTDIR}"
!include supportfiles.nsh
StrCpy $InitSupportDirDone 1
${endif}
functionend
This causes my SUPPORTDIR to be already set, as can be seen from the build log:
!define: "SUPPORTDIR"="$TEMP\Test-Proj_130911164903"
How can I change this so that the date (and folder name) is set each time the installer runs instead of at build time?
You could create a loop, starting with a 0 suffix and increasing it as long as a folder with that name exists but in you case you don't have to, just call InitPluginsDir in .onInit and use $pluginsdir as your temp folder...

Folder in start menu/installation folder still exists,After uninstallation using NSIS script?

I have written nsis script for Java project.once i have clicked uninstaller.exe
Start menu >all programs >my application
all the files are removed successfully from location of installed.but the problem is, folder in STARTMENU/installation folder still exists,after clicking uninstallation.I dont know why this happened? I have used windows 7.
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk"
Delete /REBOOTOK $INSTDIR\uninstall.exe
I have used above code.Can anyone help me?
Where is the code to remove the directory? RMDir "$SMPROGRAMS\$StartMenuGroup"
It is also important to use RequestExecutionLevel so you don't run into compatibility issues...

My NSIS script's Uninstall isn't deleting links from ProgramData directory

Got another newbie NSIS question. Here's the script:
; -*-nsis-*-
Name "ndhtest"
OutFile "FooStartMenuTest.exe"
XPStyle on
!define FOO_SRC c:\users\nhughes\foo
InstallDir "$PROGRAMFILES\Initech\"
Icon ${FOO_SRC}\foo_logo.ico
UninstallIcon ${FOO_SRC}\uninstall.ico
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
Section
SetOutPath $INSTDIR
File ${FOO_SRC}\foo.bat
WriteUninstaller "$INSTDIR\uninstall.exe"
CreateDirectory $SMPROGRAMS\Initech
CreateShortCut $SMPROGRAMS\Initech\Foo.lnk $INSTDIR\foo.bat "" \
"${FOO_SRC}\foo_logo.ico"
CreateShortCut $SMPROGRAMS\Initech\Uninstall.lnk $INSTDIR\uninstall.exe "" \
"${FOO_SRC}\uninstall.ico"
SectionEnd
Section "Uninstall"
Delete $SMPROGRAMS\Initech\Foo.lnk
Delete $SMPROGRAMS\Initech\Uninstall.lnk
RMDir $SMPROGRAMS\Initech
Delete $INSTDIR\Foo.bat
Delete $INSTDIR\uninstall.exe
RMDir $INSTDIR
SectionEnd
The uninstall seems to work except for leaving the shortcuts under ProgramData:
Directory of c:\ProgramData\Microsoft\Windows\Start Menu\Programs\Initech
08/10/2011 04:07 PM <DIR> .
08/10/2011 04:07 PM <DIR> ..
08/10/2011 04:23 PM 1,847 Foo.lnk
08/10/2011 04:23 PM 1,885 Uninstall.lnk
2 File(s) 3,732 bytes
2 Dir(s) 1,387,345,117,184 bytes free
What is my script getting wrong that is leaving this stuff hanging around?
Here is what the uninstaller writes to its console (I added a DetailPrint message listing $SMPROGRAMS):
smprograms=C:\Users\nhughes\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
Remove folder: C:\Users\nhughes\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Initech\
Delete file: C:\Program Files (x86)\Initech\foo.bat
Delete file: C:\Program Files (x86)\Initech\uninstall.exe
Remove folder: C:\Program Files (x86)\Initech\
Completed
So the links under ProgramData never get referred to, it's looking for the links under AppData\Roaming instead.
I'm testing this on Windows 7, but the core problem here is I would like to be able to write a script that works on everything from XP to Windows 7, regardless of all the changes in how Windows squirrels away stuff in different spots in different versions. This is looking like it might be painful.
If DetailPrint is added to the nsis script, it starts to be apparent that NSIS tries to create the files under C:\Users, but they are actually created in c:\ProgramData. This ProgramData directory is a strange thing, because it's not visible with dir C:\, however it's possible to enter the directory with cd. Such mysteries are caused by Virtual Store, a tricky feature of Windows 7.
Now to the solution. Windows applications should define their execution level, otherwise system may behave in an unexpected way. You remember some applications ask whether to install "for current user only" or "for all users"? That's the thing we need to declare.
If we insert nsis instruction RequestExecutionLevel user, then the shortcuts are made for current user. If we do RequestExecutionLevel admin, then we should also add SetShellVarContext all to both install and uninstall sections.
This answer is based on the article from nsis wiki: Shortcuts removal fails on Windows Vista, where examples are given for both approaches.
From the spec:
4.9.1.8 RMDir
[/r] [/REBOOTOK] directory_name
Remove the specified directory (fully qualified path with no wildcards). Without /r, the directory will only be removed if it is completely empty. If /r is specified, the directory will be removed recursively, so all directories and files in the specified directory will be removed. If /REBOOTOK is specified, any file or directory which could not have been removed during the process will be removed on reboot -- if any file or directory will be removed on a reboot, the reboot flag will be set. The error flag is set if any file or directory cannot be removed.
Try adding the /r to the RMDir lines to force it to flush the contents. Either that or remove the links individually.

Resources