No announcement yet.

$EXEDIR is set to .nsi file, NOT directory

  • Filter
  • Time
  • Show
Clear All
new posts

  • $EXEDIR is set to .nsi file, NOT directory

    Newbie to NSIS, though I've used WinAmp since 1999 I expected $EXEDIR to be set to

    But with !echo I found that it is set to

    As a consequence, operations such as CopyFiles fail. What am I doing wrong? I've attached my .nsi script.
    Attached Files

  • #2
    !echo $EXEDIR makes no sense, you need to learn the difference between compile time and run time and variables vs defines.

    You probably want "File", not "CopyFiles".

    You can't mix "RequestExecutionLevel user" and $Programfiles.
    IntOp $PostCount $PostCount + 1


    • #3
      Originally Posted by Anders View Post
      !echo $EXEDIR makes no sense, you need to learn the difference between compile time and run time and variables vs defines.

      You probably want "File", not "CopyFiles".

      You can't mix "RequestExecutionLevel user" and $Programfiles.
      Thank you for responding. I removed !echo and changed RequestExecutionLevel to admin, but now MakeNSISW throws an error about the missing Icon file, though that file is present in the directory. Seems the $EXEDIR variable is still incorrect. What am I doing wrong?

      Updated script attached.

      C:\Users\CBdeV\Documents\SecureCoop_Windows_app>dir SecureCoop.ico
      Volume in drive C has no label.
      Volume Serial Number is 980D-C70C

      Directory of C:\Users\CBdeV\Documents\SecureCoop_Windows_app

      10/07/2021 10:39 PM 4,286 SecureCoop.ico
      1 File(s) 4,286 bytes
      0 Dir(s) 268,724,682,752 bytes free


      Output from MakeNSISW:

      MakeNSIS v3.08 - Copyright 1999-2021 Contributors
      See the file COPYING for license details.
      Credits can be found in the Users Manual.

      Processing config: C:\Program Files (x86)\NSIS\nsisconf.nsh
      Processing default plugins: "C:\Program Files (x86)\NSIS\Plugins\x86-unicode\*.dll"
      + Banner::destroy
      + Banner::getWindow
      + Banner::show
      + BgImage::AddImage
      + BgImage::AddText
      + BgImage::Clear
      + BgImage:estroy
      + BgImage::Redraw
      + BgImage::SetBg
      + BgImage::SetReturn
      + BgImage::Sound
      + Dialer::AttemptConnect
      + Dialer::AutodialHangup
      + Dialer::AutodialOnline
      + Dialer::AutodialUnattended
      + Dialer::GetConnectedState
      + InstallOptions::dialog
      + InstallOptions::initDialog
      + InstallOptions::make_unicode
      + InstallOptions::show
      + KillProcWMI::KillProc
      + LangDLL::LangDialog
      + Math::Script
      + StartMenu::Init
      + StartMenu::Select
      + StartMenu::Show
      + System::Alloc
      + System::Call
      + System::Copy
      + System::Free
      + System::Get
      + System::Int64Op
      + System::Store
      + System::StrAlloc
      + TypeLib::GetLibVersion
      + TypeLib::Register
      + TypeLib::UnRegister
      + UserInfo::GetAccountType
      + UserInfo::GetName
      + UserInfo::GetOriginalAccountType
      + VPatch::GetFileCRC32
      + VPatch::GetFileMD5
      + VPatch::vpatchfile
      + advsplash::show
      + nsDialogs::Create
      + nsDialogs::CreateControl
      + nsDialogs::CreateItem
      + nsDialogs::CreateTimer
      + nsDialogs::GetUserData
      + nsDialogs::KillTimer
      + nsDialogs::OnBack
      + nsDialogs::OnChange
      + nsDialogs::OnClick
      + nsDialogs::OnNotify
      + nsDialogs::SelectFileDialog
      + nsDialogs::SelectFolderDialog
      + nsDialogs::SetRTL
      + nsDialogs::SetUserData
      + nsDialogs::Show
      + nsExec::Exec
      + nsExec::ExecToLog
      + nsExec::ExecToStack
      + nsisdl::download
      + nsisdl::download_quiet
      + splash::show

      !define: "MUI_INSERT_NSISCONF"=""

      Changing directory to: "C:\Users\CBdeV\Documents\SecureCoop_Windows_app"

      Processing script file: "C:\Users\CBdeV\Documents\SecureCoop_Windows_app\setup.nsi" (ACP)
      OutFile: "SecureCoop setup.exe"
      Name: "SecureCoop"
      Caption: "SecureCoop"
      BrandingText: " "
      InstallDir: "$PROGRAMFILES64\SecureCoop"
      Icon: "$EXEDIR/SecureCoop.ico"
      Error while loading icon from "$EXEDIR/SecureCoop.ico": can't open file
      Error in script "C:\Users\CBdeV\Documents\SecureCoop_Windows_app\setup.nsi" on line 7 -- aborting creation process

      Attached Files


      • #4
        It fails when you compile the script because $EXEDIR is only available when you run the installer ie after it's compiled.

        Basically, anything with only a '$' in front of it is a runtime variable and cannot be used at compile time.
        A '${}' (dollar sign with curly braces) is a define which can be set and changed at compile time, can also be used at runtime but is not editable ie readonly.

        The 'Icon' command is only used during compile time, and because the icon is in the same directory as the script, all you have to do is this:

        Icon SecureCoop.ico

        Same with 'UninstallIcon'.

        The 'File' command refers to the file to include ie where on your machine it is. Whereas 'SetOutPath' controls what directory that file goes into when the installer is run.
        "Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
        NSIS 3 POSIX Ninja
        Wiki Profile


        • #5
          Thank you. So would I copy a large number of files using SetOutPath and File? Tried "${EXEDIR}" and that didn't work, but when I set the path absolutely and explicitly e.g. C:\Users.. that does work. It's a workaround for now.


          • #6
            ${EXEDIR} doesn't exist because it's not a compile time variable. If you really want to set it (I would not recommend it though because it makes things more ambiguous), use: !define EXEDIR "."

            You can use the path relative to the script file, like this:

            File /r "dist/SecureCoop/*.*"

            The '/r' flag means recurse into subdirectories too (the default is to stay in the specified directory). Just be aware that any files that don't have a dot in them will be skipped (basically, files with no extension will be skipped). To include all files, use a single wildcard.

            SetOutPath just changes which directory the files go into, if you need it.

            PHP Code:
            'script.nsi, somefile.txt, and anotherfile.txt are all in the same directory.'

            relative to script path    installer output path

            "$INSTDIR"      C:\yourprogram
            "somefile.txt"        C:\yourprogram\somefile.txt
            "$INSTDIR\bin"  C:\yourprogram\bin
            "anotherfile.txt"     C:\yourprogram\bin\anotherfile.txt 
            "Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
            NSIS 3 POSIX Ninja
            Wiki Profile


            • #7
              Thank you, this did work.

              SetOutPath "$INSTDIR"
              File /r "dist\SecureCoop\*.*"