How to add a default folder always with target installation using NSIS - nsis

I want to append a default directory to my INSTALL directory always internally.
I have set it by default but if user change the directory then it not works and installed the files in the folder that user selected.
So I need append a folder ( Product name ) always internally and it can be append with the user's selected path.
Like if user selected "C:\Program Files\My Folder" then the installation should be in path "C:\Program Files\My Folder\ProductName"
Should work with the silent as well.
Can someone please advise on this.

Section MyFirstSection
StrCpy $InstDir "$InstDir\ProductName" ; Force extra sub-directory
; ...
SectionEnd
However, the recommended way to do this is to just use InstallDir without a ending backslash:
Note that the part of this string following the last \ will be used if the user selects 'browse', and may be appended back on to the string at install time (to disable this, end the directory with a \ (which will require the entire parameter to be enclosed with quotes).

Related

NSIS - How to install multiple files with similar folder structures using a single command?

Problem
I have multiple files in very similarly structured folders that I want to install in one common folder.
I can do this by manually specifying each file I want to add, like so:
SetOutPath "$INSTDIR\Final\Destination"
File /r ".\ParentFolder\Folder1\Same\Path\For\All\Thing1.ext"
File /r ".\ParentFolder\Folder2\Same\Path\For\All\Thing2.ext"
File /r ".\ParentFolder\Folder3\Same\Path\For\All\Thing3.ext"
File /r ".\ParentFolder\Folder4\Same\Path\For\All\Thing4.ext"
File /r ".\ParentFolder\Folder5\Same\Path\For\All\Thing5.ext"
However, there are 50+ of these files, and they are likely to change, so I'd prefer to do this in a way that won't require editing the NSIS in the future.
What I have Tried
I tried putting in wildcards, like so:
SetOutPath "$INSTDIR\Final\Destination"
File /r ".\ParentFolder\*\Same\Path\For\All\*.ext"
However, I get the message
File: ".\ParentFolder\*\Same\Path\For\All\*.ext" -> no files found.
Question
Is there something wrong with using multiple wildcards * in my File query?
What would be the correct way to query multiple files in different folders?
You can't put wildcards anywhere, only in the filename unfortunately.
What you can do however is to use !system to execute a batch file (or any other command or application) that writes NSIS instructions to a file you can !include:
Section
SetOutPath $InstDir
!tempfile folders ; temporary .nsh
!system 'for /D %A in (.\ParentFolder\*) do #>>"${folders}" echo File /r "%~A\Same\Path\For\All\*.ext"'
!include "${folders}"
!delfile "${folders}"
SectionEnd

How to expand to current remote path in custom command prompt in WinSCP?

I tried to make a custom command that unzip a selected file to a path defined by user, but with a default value to current path and current archive name in remote server using this command, but the prompt just gave me an empty value. What's the mistake?
unzip "!" -d "!?&Extraction Path:?!/!!"
Thanks in advance!
It's not possible. There's actually a feature request for this functionality:
Bug 743 – Allow patterns in default prompt answer in custom commands.
Though even that it meant to support only static (non-file) patterns like !/, but not file patterns like !.
If it helps, in WinSCP extensions, it's possible to use non-file patterns, like !/ (but not file patterns, like !) in default prompt/option answer.
The extension file may look like:
#name Unzip...
#side Remote
#command unzip "!" -d "%ExtractionPath%"
#option ExtractionPath -run textbox "Extraction path:" "!/"
Just store the above script to a text file and install it to WinSCP.
Another thing that you can do, is to add a checkbox that will make WinSCP add an archive name (without an extension) to the path, with some clever use of shell (bash) constructs. This way, you can uncheck the checkbox and add a custom subfolder to the target path manually, if you do not want to use the archive name for the subfolder name.
#name Unzip...
#side Remote
#command unzip "!" -d "%ExtractionPath%`[[ '%AddName%' = '1' ]] && AN=! && echo ${AN%.*}`"
#option ExtractionPath -run textbox "Extraction path:" "!/"
#option AddName -run checkbox "Add file name to the extraction path" "1" "1"
Yet another alternative is to use your own placeholder for archive name (e.g. ARCHIVENAME) that will get replaced by real name (without an extension), when the command is executed. Then, if you do not want to use the archive name for the subfolder name, you replace the ARCHIVENAME with a custom name.
#name Unzip...
#side Remote
#command unzip "!" -d "`EP=%ExtractionPath%;AN=!;AN=${AN%.*};echo ${EP/ARCHIVENAME/$AN}`"
#option ExtractionPath -run textbox "Extraction path:" "!/ARCHIVENAME"

Fail to copying file in NSIS?

For copy file i use (code below) its work properly.
Section "one"
CreateDirectory $EXEDIR\dst
CopyFiles $EXEDIR\*.* $EXEDIR/dst
SectionEnd
When i use $PROGRAMFILES(only change the destination path) it create directory but copy doesn't work.
Section "two"
CreateDirectory $PROGRAMFILES\dst
CopyFiles $EXEDIR\*.* $PROGRAMFILES/dst
SectionEnd
where is the problem?
/ is not the path separator on Windows, use \. / is supported in a lot of places but not everywhere.
It might also be failing if you don't have write access to that folder so make sure you have RequestExectionLevel Admin in your script.
The only way to know for sure is to monitor the installer with Process Monitor...

Setting an environment variable in the shortcut target

I'm writing a Inno Setup script where I need to create a shortcut that sets an environment variable in the shortcut target. The target string is something like:
cmd.exe /c set ENV_VAR=%CD% && "C:\Program Files\MyApp\MyApp.exe"
But for some reason I cannot fantom the shortcut is never created. I checked the length of the target string: 162 characters, which seems to be below the Windows (?) limit. If I create the shortcut with a target string without the "... &&" prefix and then add it by hand, it works as expected, however. Any help is appreciated.
If you want to set ENV_VAR using inno setup as %CD% and "C:\Program Files\MyApp\MyApp.exe"
you can use ; as like below
C:\Program Files;C:\Winnt;C:\Winnt\System32
this might help you
set ENV_VAR=%CD%;C:\Program Files\MyApp\MyApp.exe
I have used
set ENV_VAR=%PATH%;C:\program files
Checked after listing all,there I found
ENV_VAR=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Linux For Windows\bin;C:\Program Files (x86)\Universal Extractor;C:\Program Files (x86)\Universal Extractor\bin;C:\Program Files (x86)\Calibre2\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Subversion\bin;C:\Program Files (x86)\WinMerge;C:\Program Files
the above environment variable length is 390 characters , so I believe in your case no issue with length.

Exec not working in NSIS installer

I am new to NSIS i am trying to execute an executable while installation similar to pre request. I tried the below code which copies the exe to the installation path but it is not executing it.
Section "example" example
SetOutPath "$INSTDIR"
File "setup.exe"
Exec "$INSTDIR\setup.exe"
BringToFront
SectionEnd
The answer from Seki is mostly correct, I'd just like to add that the correct syntax for Exec/ExecWait is always Exec '"c:\path\app.exe" param1 "par am2" param3'
Parameters are of course optional but the path to the app should always be quoted, not just because in your case where $INSTDIR could contain spaces but at least on Win9x it will fail no matter what if you don't quote (According to the NSIS manual)
If the spaces/lack of quotes is not the issue then there are a couple of other things you might want to look into:
$OUTDIR is the working directory for the new process (SetOutPath sets this)
Missing dll's etc (Check with Process Monitor)
Do the $INSTDIR variable maps to a directory whose name contains spaces? If so, you should add simple quotes to include the double quotes into the Execargument :
Exec '"$INSTDIR\setup.exe"'

Resources