Search code examples
nsis

Remove \x86 from Shortcut "start in" property with NSIS Installer


I am generating a link using NSIS installer. My program did not work correctly when starting from the Desktop shortcut. So I created another shortcut by right-clicking on the desktop. The program worked. The difference is that the NSIS generated shortcut property "Start in" had c:\MyProgram\x86. The Windows generated shortcut property "Start In" just had c:\MyProgram. Is there a way from within the NSIS installer to set the property "Start in" to exclude the \x86? Here is the line that generates the shortcut:

; include library for system DLL's:
!include Library.nsh

; The name of the installer
Name "Example22.00"

; The file to write
OutFile "Example Setup 22.00.exe"

; The default installation directory
InstallDir "c:\test22\"


; Pages


UninstPage uninstConfirm
UninstPage instfiles


;--------------------------------

; The stuff to install
Section "test (required)"

  SectionIn RO
  
  
  SetOutPath "c:\test22\"
  
  ; Put file there
  ;File /oname=Example.exe "c:\Example22BuildFiles\program\Example.exe"
  file "c:\Example22BuildFiles\program\Example.exe"
  file "c:\Example22BuildFiles\program\Beep1.wav"
  file "c:\Example22BuildFiles\program\Alarm.wav"
  file "c:\Example22BuildFiles\program\Example.Application"
  file "c:\Example22BuildFiles\program\Example.exe.config"
  file "c:\Example22BuildFiles\program\Example.exe.manifest"
  file "c:\Example22BuildFiles\program\System.Data.SQLite.dll"
  file "c:\Example22BuildFiles\program\System.Data.SQLite.xml"
  file "c:\Example22BuildFiles\icon\icon.ico"

  
  SetOutPath "c:\test22\x64\"
  file "c:\Example22BuildFiles\program\x64\SQLite.Interop.dll"

  SetOutPath "c:\test22\x86\"
  file "c:\Example22BuildFiles\program\x86\SQLite.Interop.dll"

  

  WriteUninstaller "uninstall.exe"
  
  ;Create Example Folder
  CreateDirectory c:\Example
  CreateShortCut "$desktop\ExampleCSV.lnk" "c:\Example" 0
  CreateShortCut "$desktop\Example.lnk" "c:\test22\Example.exe" "" "c:\test22\icon.ico"

SectionEnd 

Solution

  • First of all, if your application relies on the working directory ("Start in") to be set to the same folder as the .exe then it is broken. The working directory can be anything if the user invokes your application with "Open with" or from a terminal. Don't read/load anything relative to .\ in your application other than filenames passed as command line parameters.

    Why does your shortcuts working directory end with \x86? Because you asked it to!

    From the CreateShortcut documentation:

    $OUTDIR is stored as the shortcut's working directory property. You can change it by using SetOutPath before creating the shortcut or use /NoWorkingDir if you don't need to set the working directory property.

    From your example $OUTDIR is set by SetOutPath "c:\test22\x86\". To set a specific directory for the shortcut, use SetOutPath before CreateShortcut.