Age gate during install when using an NSIS package - datetime

I have no idea if anyone has attempted this before (and especially considering the standards for this) but has anyone ever programmed an age gate into an NSIS installer for apps that revolve around restricted themes, content or entertainment? I ask this for the most obvious of common reasons by which a reputable marketplace would otherwise reject your submission:
The presence of sexual themes (as in "fifty shades" if you want to be extra specific)
Apps referencing the use or depiction of regulated products (beer, cannabis, vaping)
Games with extreme language or suggestive themes (ESRB Class M or equivalent)
Any ideas?

For actual games, you can register them with Windows Games Explorer. IGameExplorer::VerifyAccess can tell you if the game is blocked by parental controls. While you technically can call this method in the installer, it might give the wrong results if your installer requests UAC elevation because the installer might run under the parents account, not the child's account. The game should call it every time it is started. The Game Explorer API seems to be crippled in newer versions of Windows 10 but should work fine on Vista, 7, 8 and 8.1.
You can create a custom page in NSIS to ask for (and verify) specific information:
!include MUI2.nsh
Page Custom MyVerifyPageCreate MyVerifyPageLeave
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
!include nsDialogs.nsh
!include LogicLib.nsh
!define MIN_AGE 21
Var Age
Function MyVerifyPageCreate
!ifmacrodef MUI_HEADER_TEXT
!insertmacro MUI_HEADER_TEXT "Blah" "Blah blah blah"
!endif
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 10u 21u 100% 12u "Blah blah blah age ${MIN_AGE} blah blah"
Pop $0
${NSD_CreateNumber} 10u 35u 30u 12u "$Age"
Pop $1
nsDialogs::Show
FunctionEnd
Function MyVerifyPageLeave
${NSD_GetText} $1 $Age
${If} $Age < ${MIN_AGE}
MessageBox MB_IconStop "You must be at least ${MIN_AGE} to install $(^Name)!"
Abort
${EndIf}
FunctionEnd
Or if the user needs to enter a date:
!include MUI2.nsh
Page Custom MyVerifyPageCreate MyVerifyPageLeave
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
!include nsDialogs.nsh
!include LogicLib.nsh
!define /IfNDef GDT_VALID 0
!define /IfNDef DTS_LONGDATEFORMAT 4
!define /IfNDef /math DTM_GETSYSTEMTIME 0x1000 + 1
!define MIN_AGE 18
Function MyVerifyPageCreate
!ifmacrodef MUI_HEADER_TEXT
!insertmacro MUI_HEADER_TEXT "Blah" "Blah blah blah"
!endif
System::Call 'COMCTL32::InitCommonControlsEx(*l0x10000000008)'
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 10u 21u -20u 25u "Blah blah blah age ${MIN_AGE} blah blah$\r$\n$\r$\nEnter your birthday:"
Pop $0
nsDialogs::CreateControl SysDateTimePick32 ${DEFAULT_STYLES}|${WS_TABSTOP}|${DTS_LONGDATEFORMAT} ${__NSD_Text_EXSTYLE} 10u 50u 200u 12u "" ; Probably only works on Win98 and higher
Pop $1
nsDialogs::Show
FunctionEnd
Function MyVerifyPageLeave
; NOTE: Does not deal with leap years etc!
System::Call 'USER32::SendMessage(p$1, i${DTM_GETSYSTEMTIME}, p0, #r2)i.r0'
${If} $0 = ${GDT_VALID}
System::Call 'KERNEL32::SystemTimeToFileTime(pr2,*l.r2)'
System::Call 'KERNEL32::GetSystemTimeAsFileTime(*l.r3)' ; Current time (UTC)
System::Call 'KERNEL32::FileTimeToLocalFileTime(*lr3,*l.r3)'
System::Int64Op ${MIN_AGE} * 315360000000000 ; 1 year (KB 188768)
System::Int64Op $2 +
Pop $2
${IfThen} $2 L< $3 ${|} StrCpy $0 "OK" ${|}
${EndIf}
${If} $0 != "OK"
MessageBox MB_IconStop "You must be at least ${MIN_AGE} to install $(^Name)!"
Abort
${EndIf}
FunctionEnd

Related

How can I put a bitmap image on a browse button in NSIS?

I am working on an NSIS script. This script mainly contains customized pages.
I added a directory page using the following command:
!insertmacro MUI_PAGE_DIRECTORY
How can I add a bitmap image to an already existing "Browse..." button that will override the default text?
If you just want to use a "open folder icon" you can get it from the system:
!include WinMessages.nsh
!include LogicLib.nsh
!include nsDialogs.nsh
!include MUI2.nsh
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW CustDirShow
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
!define HIDEBROWSETEXT ; Remove "Browse..." text?
!ifdef HIDEBROWSETEXT
DirText "" "" " "
!endif
!define /ifndef FILE_ATTRIBUTE_DIRECTORY 0x10
!define /ifndef SHGFI_USEFILEATTRIBUTES 0x0010
!define /ifndef SHGFI_ICON 0x0100
!define /ifndef SHGFI_OPENICON 0x0002
!define /ifndef SHGFI_SMALLICON 0x0001
!define /ifndef SHGFI_SYSICONINDEX 0x4000
Var BrowseIcon
Function CustDirShow
${If} $BrowseIcon P= 0 ; Only load the icon once
System::Call '*(p,i,i,&t260,&t80,&l.r1)p.r0'
System::Call 'SHELL32::SHGetFileInfo(t "c:\x", i ${FILE_ATTRIBUTE_DIRECTORY}, pr0, ir1, i ${SHGFI_USEFILEATTRIBUTES}|${SHGFI_ICON}|${SHGFI_SMALLICON}|${SHGFI_OPENICON}|${SHGFI_SYSICONINDEX})'
System::Call '*$0(p.s)'
System::Free $0
Pop $BrowseIcon ; This could also be a HICON from LoadImage etc
${EndIf}
!ifdef HIDEBROWSETEXT
${NSD_AddStyle} $mui.DirectoryPage.BrowseButton ${BS_ICON}
!endif
SendMessage $mui.DirectoryPage.BrowseButton ${BM_SETIMAGE} ${IMAGE_ICON} $BrowseIcon
FunctionEnd
Function .onGUIEnd
System::Call 'USER32::DestroyIcon(p $BrowseIcon)'
FunctionEnd
You can comment out HIDEBROWSETEXT to display the text as well but that only works on Vista and later, older versions of Windows do not support image+text on a normal button.
Loading a custom .bmp bitmap can be done like this:
...
Var BrowseIcon
Function CustDirShow
${If} $BrowseIcon P= 0 ; Only load the icon once
InitPluginsDir
File "/oname=$PluginsDir\broimg.bmp" "${NSISDIR}\Contrib\Graphics\Header\nsis.bmp"
System::Call 'USER32::LoadImage(p0, t "$PluginsDir\broimg.bmp", i ${IMAGE_BITMAP}, i 16, i 16, i ${LR_LOADFROMFILE}|${LR_CREATEDIBSECTION})p.s'
Pop $BrowseIcon
${EndIf}
!ifdef HIDEBROWSETEXT
${NSD_AddStyle} $mui.DirectoryPage.BrowseButton ${BS_BITMAP}
!endif
SendMessage $mui.DirectoryPage.BrowseButton ${BM_SETIMAGE} ${IMAGE_BITMAP} $BrowseIcon
FunctionEnd
Function .onGUIEnd
System::Call 'USER32::DeleteObject(p $BrowseIcon)'
FunctionEnd
but you lose transparency etc.

Jar to exe using NSIS

so I seeking for a program (which is free) that will allow me to make from jar to exe with wrapping JRE also... til now I used Launch4J and I tried out others also but I found NSIS which is much more powerful and i think will fit what I'm looking for, but I'm having problems with defining CLASSPATH and CLASS.
Here's the code:
Name "Tool"
Caption "Internal"
Icon "UIT.ico"
OutFile "Tool.exe"
VIAddVersionKey "ProductName" "Tool"
VIAddVersionKey "Comments" "Internal"
VIAddVersionKey "CompanyName" ""
VIAddVersionKey "LegalTrademarks" ""
VIAddVersionKey "LegalCopyright" ""
VIAddVersionKey "FileDescription" "Tool"
VIAddVersionKey "FileVersion" "3.0.1934"
VIProductVersion 3.0.1934"
!define CLASSPATH "ApplicationTool.jar"
!define CLASS "v3build1934"
!define PRODUCT_NAME "Tool"
; Definitions for Java 8.0
!define JRE_VERSION "8.0"
!define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=24936&/jre-6u10-windows-i586-p.exe"
;!define JRE_VERSION "8.0"
;!define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=22933&/jre-1_5_0_16-windows-i586-p.exe"
; use javaw.exe to avoid dosbox.
; use java.exe to keep stdout/stderr
!define JAVAEXE "javaw.exe"
RequestExecutionLevel user
SilentInstall silent
AutoCloseWindow true
ShowInstDetails nevershow
!include "FileFunc.nsh"
!insertmacro GetFileVersion
!insertmacro GetParameters
!include "WordFunc.nsh"
!insertmacro VersionCompare
!include "UAC.nsh"
Section ""
Call GetJRE
Pop $R0
; change for your purpose (-jar etc.)
${GetParameters} $1
StrCpy $0 '"$R0" -classpath "${CLASSPATH}" ${CLASS} $1'
SetOutPath $EXEDIR
Exec $0
SectionEnd
; returns the full path of a valid java.exe
; looks in:
; 1 - .\jre directory (JRE Installed with application)
; 2 - JAVA_HOME environment variable
; 3 - the registry
; 4 - hopes it is in current dir or PATH
Function GetJRE
Push $R0
Push $R1
Push $2
; 1) Check local JRE
CheckLocal:
ClearErrors
StrCpy $R0 "$EXEDIR\pkg\bin\${JAVAEXE}"
IfFileExists $R0 JreFound
; 2) Check for JAVA_HOME
CheckJavaHome:
ClearErrors
ReadEnvStr $R0 "JAVA_HOME"
StrCpy $R0 "$R0\bin\${JAVAEXE}"
IfErrors CheckRegistry
IfFileExists $R0 0 CheckRegistry
Call CheckJREVersion
IfErrors CheckRegistry JreFound
; 3) Check for registry
CheckRegistry:
ClearErrors
ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\${JAVAEXE}"
IfErrors DownloadJRE
IfFileExists $R0 0 DownloadJRE
Call CheckJREVersion
IfErrors DownloadJRE JreFound
DownloadJRE:
Call ElevateToAdmin
MessageBox MB_ICONINFORMATION "${PRODUCT_NAME} uses Java Runtime Environment ${JRE_VERSION}, it will now be downloaded and installed."
StrCpy $2 "$TEMP\Java Runtime Environment.exe"
nsisdl::download /TIMEOUT=30000 ${JRE_URL} $2
Pop $R0 ;Get the return value
StrCmp $R0 "success" +3
MessageBox MB_ICONSTOP "Download failed: $R0"
Abort
ExecWait $2
Delete $2
ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\${JAVAEXE}"
IfFileExists $R0 0 GoodLuck
Call CheckJREVersion
IfErrors GoodLuck JreFound
; 4) wishing you good luck
GoodLuck:
StrCpy $R0 "${JAVAEXE}"
; MessageBox MB_ICONSTOP "Cannot find appropriate Java Runtime Environment."
; Abort
JreFound:
Pop $2
Pop $R1
Exch $R0
FunctionEnd
; Pass the "javaw.exe" path by $R0
Function CheckJREVersion
Push $R1
; Get the file version of javaw.exe
${GetFileVersion} $R0 $R1
${VersionCompare} ${JRE_VERSION} $R1 $R1
; Check whether $R1 != "1"
ClearErrors
StrCmp $R1 "1" 0 CheckDone
SetErrors
CheckDone:
Pop $R1
FunctionEnd
; Attempt to give the UAC plug-in a user process and an admin process.
Function ElevateToAdmin
UAC_Elevate:
!insertmacro UAC_RunElevated
StrCmp 1223 $0 UAC_ElevationAborted ; UAC dialog aborted by user?
StrCmp 0 $0 0 UAC_Err ; Error?
StrCmp 1 $1 0 UAC_Success ;Are we the real deal or just the wrapper?
Quit
UAC_ElevationAborted:
# elevation was aborted, run as normal?
MessageBox MB_ICONSTOP "This installer requires admin access, aborting!"
Abort
UAC_Err:
MessageBox MB_ICONSTOP "Unable to elevate, error $0"
Abort
UAC_Success:
StrCmp 1 $3 +4 ;Admin?
StrCmp 3 $1 0 UAC_ElevationAborted ;Try again?
MessageBox MB_ICONSTOP "This installer requires admin access, try again"
goto UAC_Elevate
FunctionEnd
What do i need to put in those 2 or should I move the script somewhere else for example where the netbeans project is ???
You can set environment variables for the NSIS process and child processes by calling SetEnvironmentVariable:
System::Call 'Kernel32::SetEnvironmentVariable(t "CLASSPATH", t "c:\some\path\you\got\from\the\registry")'

NSIS default install directory -- want to choose based upon install options

I'm pretty much of a novice with NSIS; but I've got a problem, and I've already looked at everything I can find on this site, as well as googling to look for answers; and so far I've got nothing.
I have an NSIS install package that I've been asked to expand so that it will install any of four related programs. However, while related, they each should install to a different folder.
I have a MUI_INSTALLOPTIONS_READ that defines four (mutually exclusive) radio buttons, and that works fine; and it does wait until after that selection to prompt for the install location. But it won't let me set different folders for each app.
The first thing I do in each branch after the MUI_INSTALLOPTIONS_READ is to set $INSTDIR to the default path for the selected application; so I would expect to use that string as the default when it calls the InstallDir; but it doesn't -- it's blank.
Of course I can't move the MUI_INSTALLOPTIONS_READ before the InstallDir in the code, because it must be in a Section; and I can't move the InstallDir after the MUI_INSTALLOPTIONS_READ, because it CANNOT be in a Section (or a Function). I have tried splitting the section that contains the MUI_INSTALLOPTIONS_READ, so that there's some space between it and the next section, and inserting the InstallDir in that space; but that changed nothing.
Anyone know of a way to do what I'm trying to do? Thanks for any suggestions you can offer.
!ifndef PRODUCT_VERSION
!error "Version required ! Usage: makensisw.exe /DPRODUCT_VERSION=version scriptfile.nsi"
!endif
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "ProductX"
!define PRODUCT_PUBLISHER "ACME Technologies"
!define PRODUCT_WEB_SITE "http://www.google.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
; MUI 1.67 compatible ------
!include "MUI.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; Full Install or Demo page
Page custom FIOrDemo
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "English"
;Reserve Files
ReserveFile "appSelect.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; Variables
Var APP1_INSTALL
Var APP2_INSTALL
Var APP3_INSTALL
Var APP4_INSTALL
; MUI end ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir $INSTDIR
; InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
Section "Main Section" SEC01
SetOutPath "$INSTDIR"
SetOverwrite try
SetShell VarContext all
; pop $0
; ${While} $0 != "Marker"
; DetailPrint 'Extra info: $0'
; pop $0
; ${EndWhile}
; Pop $0 ; restore
!insertmacro MUI_INSTALLOPTIONS_READ $APP2_INSTALL "appSelect.ini" "Field 2" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $APP1_INSTALL "appSelect.ini" "Field 3" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $APP3_INSTALL "appSelect.ini" "Field 4" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $APP4_INSTALL "appSelect.ini" "Field 5" "State"
DetailPrint 'Install selection $APP2_INSTALL $APP1_INSTALL $APP3_INSTALL $APP4_INSTALL '
StrCmp $APP1_INSTALL 1 app1_selected
StrCmp $APP2_INSTALL 1 app2_selected
StrCmp $APP3_INSTALL 1 app3_selected
StrCmp $APP4_INSTALL 1 app4_selected
Goto continue
app1_selected:
Strcpy $INSTDIR "$PROGRAMFILES\Folder1"
Call InstallApp1
Goto continue
app2_selected:
Strcpy $INSTDIR "$PROGRAMFILES\Folder2"
Call InstallApp2
Goto continue
app3_selected:
Strcpy $INSTDIR "$PROGRAMFILES\Folder3"
Call InstallApp3
Goto continue
app4_selected:
Strcpy $INSTDIR "$PROGRAMFILES\Folder4"
Call InstallApp4
Goto continue
continue:
SectionEnd
Section -Post
; Force reboot after install
MessageBox MB_ICONINFORMATION|MB_OK "Installation complete. Your computer will now restart."
; Reboot
SectionEnd
Function InstallApp1
;Copy all application files
FunctionEnd
Function InstallApp2
;Copy all application files
FunctionEnd
Function InstallApp3
;Copy all application files
FunctionEnd
Function InstallApp4
;Copy all application files
FunctionEnd
Function .onInit
;Extract InstallOptions INI files
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "appSelect.ini"
FunctionEnd
Function FIOrDemo
!insertmacro MUI_HEADER_TEXT "Choose Installation Type" ""
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "appSelect.ini"
FunctionEnd
Try setting $InstDir in the leave callback for your custom page or the pre callback for the directory page. I would also recommend that you use a section for each app, then you could do all the configuration before you get to the instfiles page.
It is also possible to use the components page with the radio helper macros in sections.nsh instead of your custom page...
!include MUI.nsh
!include LogicLib.nsh
Page Custom MyCustomPageCreate MyCustomPageLeave
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Function .onInit
InitPluginsDir
WriteIniStr "$PluginsDir\page.ini" Settings NumFields 2
WriteIniStr "$PluginsDir\page.ini" "Field 1" Type RadioButton
WriteIniStr "$PluginsDir\page.ini" "Field 1" Text "App 1"
WriteIniStr "$PluginsDir\page.ini" "Field 1" State 1
WriteIniStr "$PluginsDir\page.ini" "Field 1" Left 20
WriteIniStr "$PluginsDir\page.ini" "Field 1" Right -10
WriteIniStr "$PluginsDir\page.ini" "Field 1" Top 20
WriteIniStr "$PluginsDir\page.ini" "Field 1" Bottom 40
WriteIniStr "$PluginsDir\page.ini" "Field 2" Type RadioButton
WriteIniStr "$PluginsDir\page.ini" "Field 2" Text "App 2"
WriteIniStr "$PluginsDir\page.ini" "Field 2" Left 20
WriteIniStr "$PluginsDir\page.ini" "Field 2" Right -10
WriteIniStr "$PluginsDir\page.ini" "Field 2" Top 40
WriteIniStr "$PluginsDir\page.ini" "Field 2" Bottom 60
FunctionEnd
Function MyCustomPageCreate
!insertmacro INSTALLOPTIONS_DISPLAY "page.ini"
FunctionEnd
Function MyCustomPageLeave
!insertmacro MUI_INSTALLOPTIONS_READ $0 "page.ini" "Field 1" "State"
${If} $0 <> 0
StrCpy $InstDir "$ProgramFiles\App1"
${Else}
StrCpy $InstDir "$ProgramFiles\App2"
${EndIf}
FunctionEnd

nsis radiobuttons, not on onclick to call function, but after click "next"

i´m new here and in nsis. I have a nsis script with some custompages an radiobuttons.
My problem is that when I choose a radiobutton the function is called immediately. And I want it after the "Next" click. I know thats because the NSD_OnClick, but is the a alternative?
Here is some code:
Function plugins
nsDialogs::Create 1018
Pop $Dialog
${NSD_CreateLabel} 0 0 100% 16u "Install Plugins?:"
${NSD_CreateRadioButton} 20 40 100% 12u "Yes"
Pop $hwnd
${NSD_AddStyle} $hwnd ${WS_GROUP}
${NSD_OnClick} $hwnd Yes
${NSD_CreateRadioButton} 20 60 100% 12u "No"
Pop $hwnd
${NSD_OnClick} $hwnd No
nsDialogs::Show
FunctionEnd
Function Yes
;Install Plugins...
FunctionEnd
You could keep the state of your radiobutton in the Yes callback and later in a leaving callback of your plugins custom page choose to install or not depending on the state.
Roughly :
Var isSelected
Function Yes
StrCpy $isSelected 1
FunctionEnd
Function No
StrCpy $isSelected 0
FunctionEnd
Function PlunginsLeavePage #<--you need to declare that in the "Page Custom"
${if} $isSelected = 1
;Install Plugins (this was formerly in the Yes function)
${endIf}
FunctionEnd

fill directory textbox on button click in MUI NSI Installer , using ButtonEvent plug-in

i have added custom button using Resource Hacker on the MUI Directory Page of the installer, now i want that when the button is clicked then the Default Textbox where the user enters the InstallDir (the path where the application is installed), is filled with some specified text. please help me with the code?
I am using ButtonEvent plug-in, but i don't know what code to write in the event handler. Currently am just displaying a message box when the button is clicked to ensure that the event is working.
Please help.
!define IDC_BUTTON_SETPATH 1200 (1200 is the ID OF THE BUTTON ADDED from Resource hacker)
;Pages
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW DirectoryShow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE DirectoryLeave
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
;--------------------------------
Function buttonclicked
MessageBox MB_OK|MB_ICONEXCLAMATION "You Clicked Me "
Abort
FunctionEnd
# Occurs on installer UI initialization.
Function myGuiInit
# Create event handler for our parent window button.
GetFunctionAddress $R3 buttonclicked
ButtonEvent::AddEventHandler ${IDC_BUTTON_SETPATH} $R3
FunctionEnd
------------------------NEW EDITED PART-- CODE FOR THREE CUSTOM BUTTONS-------------------
!include MUI2.nsh
; --------------------------------------------------
!define IDC_BUTTON_CDRIVEPATH 1200
!define IDC_BUTTON_DDRIVEPATH 1201
!define IDC_BUTTON_EDRIVEPATH 1202
; --------------------------------------------------
# The event handler for our parent button is added in MyGUIInit.
!define MUI_CUSTOMFUNCTION_GUIINIT myGuiInit
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\pksicon.bmp" ; optional
!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\pksleftimage.bmp" ;
;--------------------------------
XPStyle on
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\licensefile.txt"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW DirectoryShow
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
; --------------------------------------------------
; Languages.
!insertmacro MUI_LANGUAGE English
; --------------------------------------------------
!macro SetDirPageInstallDir text
!if "${MUI_SYSVERSION}" < "2.0"
Push $0
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 0x3FB
SendMessage $0 ${WM_SETTEXT} 0 "STR:${text}"
Pop $0
!else
SendMessage $mui.DirectoryPage.Directory ${WM_SETTEXT} 0 "STR:${text}"
!endif
!macroend
# Called when the CDRIVEPATH button is pressed.
Function CDRIVEPATH
MessageBox MB_OK|MB_ICONEXCLAMATION "The Software will be installed in : C:\ "
;In buttonclicked handler
!insertmacro SetDirPageInstallDir "C:\"
FunctionEnd
;--------------------------------
Function DDRIVEPATH
MessageBox MB_OK|MB_ICONEXCLAMATION "The Software will be installed in : D:\ "
;In buttonclicked handler
!insertmacro SetDirPageInstallDir "D:\"
FunctionEnd
;--------------------------------
Function EDRIVEPATH
MessageBox MB_OK|MB_ICONEXCLAMATION "The Software will be installed in : E:\ "
;In buttonclicked handler
!insertmacro SetDirPageInstallDir "E:\"
FunctionEnd
;--------------------------------
InstallDir $INSTDIR
# Occurs on installer UI initialization.
Function myGuiInit
# Create event handler for our parent window button.
GetFunctionAddress $R0 CDRIVEPATH
ButtonEvent::AddEventHandler ${IDC_BUTTON_CDRIVEPATH} $R0
; GetFunctionAddress $R1 EDRIVEPATH **-----this line causes error**
; ButtonEvent::AddEventHandler ${IDC_BUTTON_DDRIVEPATH} $R1 -----this line causes error
; GetFunctionAddress $R2 EDRIVEPATH **-----this line causes error**
; ButtonEvent::AddEventHandler ${IDC_BUTTON_EDRIVEPATH} $R2 -----this line causes error
FunctionEnd
;------------------------------------------------
# Occurs on Directory page show.
Function DirectoryShow
# Create event handler for our Directory page button. /NOTIFY makes
# the button move to the next page when clicked.
ButtonEvent::AddEventHandler ${IDC_BUTTON_CDRIVEPATH}
ButtonEvent::AddEventHandler ${IDC_BUTTON_DDRIVEPATH}
ButtonEvent::AddEventHandler ${IDC_BUTTON_EDRIVEPATH}
# Disable next button.
GetDlgItem $R0 $HWNDPARENT 1
EnableWindow $R0 0
FunctionEnd
; --------------------------------------------------
;General
;Name and file
Name NEW_FILL_TEXTBOX_BUTTONCLICK
OutFile NEW_FILL_TEXTBOX_BUTTONCLICK.exe
Section
DetailPrint "SUCCESSFULLY INSTALLED"
SectionEnd
You did not say which version of the MUI you are using, this macro should handle both...
!macro SetDirPageInstallDir text
!if "${MUI_SYSVERSION}" < "2.0"
Push $0
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 0x3FB
SendMessage $0 ${WM_SETTEXT} 0 "STR:${text}"
Pop $0
!else
SendMessage $mui.DirectoryPage.Directory ${WM_SETTEXT} 0 "STR:${text}"
!endif
!macroend
;In buttonclicked handler
!insertmacro SetDirPageInstallDir "$programfiles\Hello World"

Resources