Announcement

Collapse
No announcement yet.

Create shortcut optionally by commandline

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create shortcut optionally by commandline

    Hi,

    I try to add a command line option to enable Shortcut Creation in my NSIS script - but it's not working as expected.

    I use the SHOWREADME options to show the checkbox in the last page of the installation wizard - and add the following line to Init function

    code:

    Function .onInit

    ${GetOptions} $CMDLINE "/NoShortcut" $commandLineNoShortcut
    ${If} $commandLineNoShortcut == "=1"
    !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
    ${EndIf}

    But it seems that the command

    code:
    !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
    do not work at this part of the script - the checkbox is always checked! Also if if use the checked command line option - how can I customize my script that it use my command line option? Can I set the value for MUI_FINISHPAGE_SHOWREADME_NOTCHECKED?

    Thanks in advance
    Oliver

  • #2
    You cannot use a define like that. You must toggle the checkbox in the finish page show callback function.
    IntOp $PostCount $PostCount + 1

    Comment


    • #3
      Ok thanks for your replay - and how can I do this? Short code example would be very helpful - thanks again

      Comment


      • #4
        PHP Code:
        Function DoWhatever
        MessageBox mb_ok Whatever
        FunctionEnd

        !include "MUI2.nsh"
        !insertmacro MUI_PAGE_COMPONENTS
        !insertmacro MUI_PAGE_INSTFILES
        !define MUI_FINISHPAGE_SHOWREADME
        !define MUI_FINISHPAGE_SHOWREADME_TEXT "Do whatever"
        !define MUI_FINISHPAGE_SHOWREADME_FUNCTION DoWhatever
        !define MUI_PAGE_CUSTOMFUNCTION_SHOW ConfigureFinishPage
        !insertmacro MUI_PAGE_FINISH
        !insertmacro MUI_LANGUAGE "English"

        !include nsDialogs.nsh
        !include FileFunc.nsh
        Function ConfigureFinishPage
        !if "${MUI_SYSVERSION}>= 2.0
            StrCpy 
        $1 $mui.FinishPage.ShowReadme
        !else
            
        GetDlgItem $1 $MUI_HWND 0x4B3
        !endif
        ${
        GetOptions$CMDLINE "/NoShortcut" $0
        ${If} $== "=1"
            
        ${NSD_Uncheck} $1
        ${EndIf}
        FunctionEnd 
        IntOp $PostCount $PostCount + 1

        Comment


        • #5
          Thanks for the quick replies and the script - but unfortunately it is not working correctly

          $mui.FinishPage.ShowReadme

          is always empty - I put a messagebox in my script to show the content of this variable - always empty - I run it with NSIS 2.x...

          Comment


          • #6
            It worked in NSIS 3 when I tried. Download WinSpy++ and get the id of the control and use the GetDlgItem instead like I did with MUI v1 as an alternative.

            $mui.FinishPage.ShowReadme is only valid in the show and leave callback for the finish page.
            IntOp $PostCount $PostCount + 1

            Comment


            • #7
              I removed everything not needed in my script and tried again with NSIS 3.03 - the messagebox pop up before the first page is displayed (is this really correct?) - perhaps you can find the issue - this is my script that I'm trying to run - add only one example file (sync.txt) as content - and perhaps you can also tell me if this will also work in silent mode - i guess it will not work - that would be my next question

              code:

              !define MULTIUSER_EXECUTIONLEVEL Highest
              !define MULTIUSER_MUI
              !define MULTIUSER_INSTALLMODE_COMMANDLINE

              !include "MUI2.nsh"
              !include "MultiUser.nsh"
              !include "FileFunc.nsh"
              !include "LogicLib.nsh"
              !include "nsDialogs.nsh"

              ;Basic Config
              Name "MyTest"
              BrandingText "MyTest"
              OutFile "MyTest.exe"
              InstallDir "$PROGRAMFILES\MyTest"
              InstallDirRegKey HKCU "Software/MyTest" "InstallDir"


              ;Version Information
              VIProductVersion "1.0.0.0"
              VIAddVersionKey "ProductName" "MyTest"

              ;Request application privileges for Windows Vista
              RequestExecutionLevel admin



              ;Design
              !define MUI_HEADERIMAGE
              !define MUI_HEADER_TRANSPARENT_TEXT
              !define MUI_FINISHPAGE_TITLE_3LINES

              !define MUI_FINISHPAGE_SHOWREADME ""
              !define MUI_FINISHPAGE_SHOWREADME_TEXT "Create Desktop Shortcut"
              !define MUI_FINISHPAGE_SHOWREADME_FUNCTION createdesktopshortcut
              !define MUI_PAGE_CUSTOMFUNCTION_SHOW ConfigureFinishPage

              ;Install Pages
              !insertmacro MULTIUSER_PAGE_INSTALLMODE
              !insertmacro MUI_PAGE_DIRECTORY
              !insertmacro MUI_PAGE_INSTFILES
              !define MUI_FINISHPAGE_NOAUTOCLOSE

              # settings to start application
              !define MUI_FINISHPAGE_RUN_NOTCHECKED
              !define MUI_FINISHPAGE_RUN_Text "Start #Productname#"
              !define MUI_FINISHPAGE_RUN "$INSTDIR\ASGRD.exe"
              !insertmacro MUI_PAGE_FINISH

              ;Uninstall Pages
              !insertmacro MUI_UNPAGE_CONFIRM
              !insertmacro MUI_UNPAGE_INSTFILES

              ;Set Language
              !insertmacro MUI_LANGUAGE "English"


              ;--------------------------------
              ;Set checkbox in show finish page

              Function ConfigureFinishPage
              !if "${MUI_SYSVERSION}" >= 2.0
              MessageBox MB_OK $mui.FinishPage.ShowReadme
              StrCpy $1 $mui.FinishPage.ShowReadme
              !else
              GetDlgItem $1 $MUI_HWND 0x4B3
              !endif

              ${GetOptions} $CMDLINE "/NoShortcut" $0

              ${If} $0 == "=1"
              ${NSD_Uncheck} $1
              ${EndIf}
              FunctionEnd

              ;--------------------------------
              ;Installer Functions

              Function .onInit

              !insertmacro MUI_LANGDLL_DISPLAY
              !insertmacro MULTIUSER_INIT

              FunctionEnd

              ;--------------------------------
              ;CreateDesktopShortcut Functions
              Function createdesktopshortcut
              CreateShortCut "$DESKTOP\MyTest.lnk" "$INSTDIR\sync.txt"
              FunctionEnd

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

              Section "!Core components" Section_CoreInstall
              SectionIn RO
              SetOutPath $INSTDIR

              ;AddFiles
              File sync.txt

              ;Start Menu
              CreateDirectory "$SMPROGRAMS\MyTest"

              ;Registry
              WriteRegStr HKCU "Software/MyTest" "InstallDir" $INSTDIR

              SectionEnd


              Comment


              • #8
                You put the MUI_FINISHPAGE_SHOWREADME defines too early in the .nsi, they must come right before the insertmacro finishpage line. Look at my example!

                MUI_PAGE_CUSTOMFUNCTION_SHOW is a generic macro define and only applies to the next page and you must place it correctly!
                IntOp $PostCount $PostCount + 1

                Comment


                • #9
                  Ok thanks a lot - now it works - really great support

                  Is there any chance to disable it also using silent mode? (/S /NoShortcut=1)?

                  Comment


                  • #10
                    Seems to work also in silent mode

                    Comment


                    • #11
                      LogicLib.nsh has a if check for silent you can use if you want to detect just /S
                      IntOp $PostCount $PostCount + 1

                      Comment

                      Working...
                      X
                      😀
                      🥰
                      🤢
                      😎
                      😡
                      👍
                      👎