Archive: Check if user selected "Reboot now" when using SetRebootFlag


Check if user selected "Reboot now" when using SetRebootFlag
  While installing my application I use the SetRebootFlag. On the finish page, I want to know what the user selected after pressing finish.

The reason I need to know is because if "Reboot Manually Later" is selected I want to start the application.

I've searched around and can't seem to get it working.
One thing I read about is using the page callback function, but how do I do this? And how do I know what the user selected?

Any help is welcome!, I really need all the help I can get for this.


add a 'MUI_PAGE_CUSTOMFUNCTION_LEAVE function' before your MUI Finish page, then based on whether you use MUI or MUI2, do something like the following in that callback function:

MUI:
Read $PLUGINSDIR\ioSpecial.ini [Field 4] State
Read $PLUGINSDIR\ioSpecial.ini [Field 5] State

If Field 4's State = 1, then the user chose 'reboot now'.
If Field 5's State = 1, then the user chose 'I want to manually reboot later'.

MUI2:


FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $R0 0x4b3
${NSD_GetState} $0 $1
GetDlgItem $0 $R0 0x4b4
${NSD_GetState} $0 $2
MessageBox MB_OK "Reboot now: [$1]$\r$\nReboot later: [$2]"
Abort

And perform the desired action (Reboot / Launch your app) based on the states of $1 and $2.

Thank you!

I got it working.

Thx for helping me :)


No prob :)

I wonder if MUI2 could store these pre-set dialogs' settings in pre-defined variables. Would waste a bit of memory if unused, but I think there's been a steady trend of making NSIS a bit easier to use at the cost of superlean installers (e.g. recommendations to use LogicLib, despite the overhead that generates) - so maybe they'll add that. I'm glad the above works, regardless :)


@Animaether
Thanks for your info.

One question, is there any way to get status of the MUI_FINISHPAGE_SHOWREADME checkbox?

I used to use
!insertmacro INSTALLOPTIONS_READ $MUI_TEMP1 "ioSpecial.ini" "Field 5" "State"
to get the state of it. Now I use MUI2 and nsDialog. it doesn't work any more as there is no ioSpecial.ini in MUI2.

Thanks.


Use WinSpy / WinSpy++ / process explorer / whathaveyou to get the control ID of that checkbox, then use GetDlgItem to get the hwnd for that control, after which you should be able to use '${NSD_GetState} <hwnd> <out var>' to get its checked state.
The control ID should never vary (until somebody mucks with the resources of MUI2), the hwnd does, so you have to look that up via the aforementioned.


Originally posted by Animaether
Use WinSpy / WinSpy++ / process explorer / whathaveyou to get the control ID of that checkbox, then use GetDlgItem to get the hwnd for that control, after which you should be able to use '${NSD_GetState} <hwnd> <out var>' to get its checked state.
The control ID should never vary (until somebody mucks with the resources of MUI2), the hwnd does, so you have to look that up via the aforementioned.
I did use winspy++ to check the control id, it is 0x4b4.

This is what i tried to do:

FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $R0 0x4b4
${NSD_GetState} $0 $1
MessageBox MB_OK "State of SHOW_READ_ME checkbox: $1"

But, it always shows 0.
Do i do anything wrong?

not sure how you got the 0x4b4 - I think it should be 0x4b3 (as stated in WinSpy++ , don't add 1)


!include "MUI2.NSH"
outfile 'finishpage_readme_checkbox_test.exe'

Section
SectionEnd

!define MUI_FINISHPAGE_SHOWREADME "http://www****n.com/"
!define MUI_FINISHPAGE_SHOWREADME_TEXT "HELLO"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION myFunc
!insertmacro MUI_LANGUAGE "English"
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE LeaveFunc
!insertmacro MUI_PAGE_FINISH

Function myFunc
MessageBox MB_OK "Test"
FunctionEnd

Function LeaveFunc
MessageBox MB_OK "Leave"
FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $R0 0x4b3
${NSD_GetState} $0 $1
MessageBox MB_OK "State of SHOW_READ_ME checkbox: $1"
Abort
FunctionEnd

Originally posted by Animaether
not sure how you got the 0x4b4 - I think it should be 0x4b3 (as stated in WinSpy++ , don't add 1)


!include "MUI2.NSH"
outfile 'finishpage_readme_checkbox_test.exe'

Section
SectionEnd

!define MUI_FINISHPAGE_SHOWREADME "http://www****n.com/"
!define MUI_FINISHPAGE_SHOWREADME_TEXT "HELLO"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION myFunc
!insertmacro MUI_LANGUAGE "English"
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE LeaveFunc
!insertmacro MUI_PAGE_FINISH

Function myFunc
MessageBox MB_OK "Test"
FunctionEnd

Function LeaveFunc
MessageBox MB_OK "Leave"
FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $R0 0x4b3
${NSD_GetState} $0 $1
MessageBox MB_OK "State of SHOW_READ_ME checkbox: $1"
Abort
FunctionEnd
it is 0x4b4 for me and i know why mine doesn't work. i didnt use leavefunc, i place it in somewhere else. Probably it calls after this control has been removed.

Thanks for your kindly help.

huh.. that's odd. I wonder why it would be 0x4b4 for you as, again, that number shouldn't change.. anyway, glad the sample code helped resolve it regardless :)


i tried to build upon this, as i'm trying to enable/disable MUI_FINISHPAGE_SHOWREADME at runtime.

FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $R0 0x4b4
${If} $WebsiteURL == ""
EnableWindow $0 0
${Else}
EnableWindow $0 1
${EndIf}

didn't work, any ideas?

Probably the wrong ID again.. seems this varies a bit between versions. Of course using the ID directly is unnecessary with most of MUI as it actually stores the hwnds in variables internally. You can peek at the files in "\Contrib\Modern UI 2\" to find those variables.

In this case, $mui.FinishPage.ShowReadme should be it.


insertmacro MUI_LANGUAGE English 

>
You might want to add code that unchecks the checkbox as well as the above 'as is' can lead to the situation of the control being disabled but checked... which is atypical behavior (but may be desired).