Old 12th April 2018, 07:00   #1
OliverM
Junior Member
 
Join Date: Apr 2018
Posts: 6
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
OliverM is offline   Reply With Quote
Old 12th April 2018, 10:28   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,840
You cannot use a define like that. You must toggle the checkbox in the finish page show callback function.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 12th April 2018, 12:46   #3
OliverM
Junior Member
 
Join Date: Apr 2018
Posts: 6
Ok thanks for your replay - and how can I do this? Short code example would be very helpful - thanks again
OliverM is offline   Reply With Quote
Old 12th April 2018, 15:31   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,840
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
Anders is offline   Reply With Quote
Old 13th April 2018, 09:04   #5
OliverM
Junior Member
 
Join Date: Apr 2018
Posts: 6
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...
OliverM is offline   Reply With Quote
Old 13th April 2018, 09:48   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,840
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
Anders is offline   Reply With Quote
Old 13th April 2018, 10:29   #7
OliverM
Junior Member
 
Join Date: Apr 2018
Posts: 6
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


OliverM is offline   Reply With Quote
Old 13th April 2018, 10:36   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,840
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
Anders is offline   Reply With Quote
Old 13th April 2018, 10:45   #9
OliverM
Junior Member
 
Join Date: Apr 2018
Posts: 6
Ok thanks a lot - now it works - really great support

Is there any chance to disable it also using silent mode? (/S /NoShortcut=1)?
OliverM is offline   Reply With Quote
Old 13th April 2018, 10:51   #10
OliverM
Junior Member
 
Join Date: Apr 2018
Posts: 6
Seems to work also in silent mode
OliverM is offline   Reply With Quote
Old 13th April 2018, 11:10   #11
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,840
LogicLib.nsh has a if check for silent you can use if you want to detect just /S

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Tags
command line options, nsis, shortcut

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump