Archive: In need of help creating a custom page.


In need of help creating a custom page.
I have written a program specifically for Windows XP. This program requires the Hibernate function in XP to be enabled. After some research on how to check if the Hibernate function is enabled there will be a "hiberfil.sys" file marked as system, hidden on the root drive.

In the installer I want to make a page where if "hiberfil.sys" does not exist it will display a page with a checkbox ensuring the user knows they are enabling Hibernate. The "Next >" button can not be clickable unless the checkbox is checked. Once "Next >" is clicked it will tell the installer to execute "powercfg.exe /hibernate on" during the install portion. But, if "hiberfil.sys" DOES exist, it will not display the page and will not run the command.

Here are my questions: Is this possible to create and preform the way I would like it to?

And if so, how would my script look and what would the checkbox field look like in my custom page file?


!include nsDialogs.nsh
!include LogicLib.nsh

Name nsDialogs
OutFile nsDialogs.exe
ShowInstDetails show

XPStyle on

Var CreateDialog
Var Dialog
Var checkbox
Var Checkbox_State


Page custom nsDialogsPage nsDialogsPageLeave
page license
Page instfiles



Function nsDialogsPage

${If} $CreateDialog = 1

GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 $Checkbox_State

nsDialogs::Create /NOUNLOAD 1018
Pop $Dialog

${IfThen} $Dialog == error ${|} Abort ${|}

${NSD_CreateCheckbox} 60 60u 100% 10u "Enable Hibernate"
Pop $Checkbox

${If} $Checkbox_State == ${BST_CHECKED}
${NSD_SetState} $Checkbox $Checkbox_State
${EndIf}

${NSD_OnClick} $Checkbox nsDialogsPageCheckboxChange

nsDialogs::Show

${Else}

Abort

${EndIf}

FunctionEnd


Function nsDialogsPageLeave

${NSD_GetState} $Checkbox $Checkbox_State
MessageBox MB_OK "CheckBox State:$\n$\n[$Checkbox_State]"

FunctionEnd


Function nsDialogsPageCheckboxChange

Pop $0

${NSD_GetState} $Checkbox $Checkbox_State

GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 $Checkbox_State

FunctionEnd


Function .onInit

ReadEnvStr $0 SYSTEMDRIVE

${Unless} ${FileExists} "$0\hiberfil.sys"

StrCpy $CreateDialog 1

${EndUnless}

StrCpy $Checkbox_State 0

FunctionEnd




Section -

${If} $Checkbox_State = 1

DetailPrint "Condition is true to execute powercfg.exe /hibernate"

${EndIf}

DetailPrint "hello world"

SectionEnd

I forgot to state I am using the Modern UI and I wanting to use a custom page. Assuming you can do this with the standard UI, I believe you would be able to do this in the Modern UI, correct?

However, the script works great with the standard UI.


Sorry, my fault...

!include nsDialogs.nsh
!include LogicLib.nsh

!include MUI2.nsh

Name nsDialogs
OutFile nsDialogs.exe
ShowInstDetails show

XPStyle on

Var CreateDialog
Var Dialog
Var checkbox
Var Checkbox_State


Page custom nsDialogsPage nsDialogsPageLeave
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\COPYING"
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_LANGUAGE "English"

Function nsDialogsPage

!insertmacro MUI_HEADER_TEXT "nsDialogs custom page" "Enable Hibernate to continue"

${If} $CreateDialog = 1

GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 $Checkbox_State

nsDialogs::Create /NOUNLOAD 1018
Pop $Dialog

${IfThen} $Dialog == error ${|} Abort ${|}

${NSD_CreateCheckbox} 60 60u 100% 10u "Enable Hibernate"
Pop $Checkbox

${If} $Checkbox_State == ${BST_CHECKED}
${NSD_SetState} $Checkbox $Checkbox_State
${EndIf}

${NSD_OnClick} $Checkbox nsDialogsPageCheckboxChange

nsDialogs::Show

${Else}

Abort

${EndIf}

FunctionEnd


Function nsDialogsPageLeave

${NSD_GetState} $Checkbox $Checkbox_State
MessageBox MB_OK "CheckBox State:$\n$\n[$Checkbox_State]"

FunctionEnd


Function nsDialogsPageCheckboxChange

Pop $0

${NSD_GetState} $Checkbox $Checkbox_State

GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 $Checkbox_State

FunctionEnd


Function .onInit

ReadEnvStr $0 SYSTEMDRIVE

${Unless} ${FileExists} "$0\hiberfil.sys"

StrCpy $CreateDialog 1

${EndUnless}

StrCpy $Checkbox_State 0

FunctionEnd




Section -

${If} $Checkbox_State = 1

DetailPrint "Condition is true to execute powercfg.exe /hibernate"

${EndIf}

DetailPrint "hello world"

SectionEnd