How to add directory and sub directories in installer package - nsis

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

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.

NSIS script - Uninstall.exe file alone not getting deleted

I am using the below statements to delete the files and subdirectories from the installed directory.
RMDir /r "$INSTDIR\*.*"
RMDir "$INSTDIR"
While uninstalling, it doesn't delete the uninstall.exe file alone from the installed directory.
Please let me know your suggestions on this.
Have you tried the /REBOOTOKflag?
Take notice of this warning from the scripting reference:
Warning: using RMDir /r $INSTDIR in the uninstaller is not safe.
Though it is unlikely, the user might select to install to the Program
Files folder and so this command will wipe out the entire Program
Files folder, including other programs that has nothing to do with the
uninstaller. The user can also put other files but the program's files
and would expect them to get deleted with the program. Solutions are
available for easily uninstalling only files which were installed by
the installer.

NSIS Uninstaller wont unistall files that werent in the same directory as the .nsi during compile

I have been trying to add in an Uninstall only installed files function into my NSIS installer using the Uninstall only installed files tutorial that can be found here
The example works fine when I only add files to the installer that are in the same directory as the .nsi source file. For example adding a file using this command:
${File} "file.txt"
The file file.txt is installed and can also deleted when you run the uninstaller. However if I place file.txt into a subdirectory called Files and use the command:
${File} "Files\file.txt"
The file.txt file will be installed correctly, but when I run the uninstaller it wont be deleted.
Am I missing something obvious with NSIS here?
May be one of the following two reasons:-
In your $InstDir Files\File.txt is just included like $InstDir\File.txt whereas Uninstaller is trying to Delete $InstDir\Files\File.txt.
In your $InstDir Files\File.txt is included like $InstDir\Files\File.txt But your Uninstaller is trying to Delete $InstDir\File.txt.

specificing destination directory in nsis (zipped installation)

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.

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