- NSIS Discussion
- Please help me with command reboot
Archive: Please help me with command reboot
sunlight112
5th February 2007 04:39 UTC
Please help me with command reboot
Hi all,
I create installer with page finish which requires user to reboot.
I also set reboot flag in section or function or .onInit. My problem is:
Sometimes, my installer reboot.
I also read many information on forum about reboot. I aslo use reboot command in my installer like this
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION FinishShow
!insertmacro MUI_PAGE_FINISH
Section -
SetOutPath $INSTDIR
SetRebootFlag true
SectionEnd
Function FinishShow
IfRebootFlag 0 noreboot
Reboot
noreboot:
FunctionEnd
I do not understand why sometimes it reboot and sometimes it is not.
If it works, it only close some windows which I is opening
Please help me!
I try my best to find a solution but I can not.
My word is too bad if you do not understand, please tell me!
Thank a lot,
sunlight112
5th February 2007 12:12 UTC
I am sorry for reply myself,
I only want to make clear my ideas,
Eg:
My installer which requires user to reboot ===> the first installer.
I add it in another installer====>the second installer (in this case, it has the first installer)
Firstly, I run with the first installer, it reboot well.
However, I run the second installer (it has included the first), I click "REBOOT NOW", It does not work.
I only want to know how can I force my installer reboot if user check "REBOOT NOW" on finish page.
Actually, I has read carefully these information on our forum but this is not anything about my mistake
If you use to see this problem, please help me!
Your help is very useful for me!
Thank a lot,
Red Wine
5th February 2007 14:09 UTC
Actually you do not need these:
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION FinishShow
!insertmacro MUI_PAGE_FINISH
The MUI system is intelligent enough to know when reboot is needed ;)
example:
;NSIS Modern User Interface
;Welcome/Finish Page Example Script
;Written by Joost Verburg
;--------------------------------
;Include Modern UI
!include "MUI.nsh"
;--------------------------------
;General
;Name and file
Name "Modern UI Test"
OutFile "WelcomeFinish.exe"
;Default installation folder
InstallDir "$PROGRAMFILES\Modern UI Test"
;Get installation folder from registry if available
InstallDirRegKey HKCU "Software\Modern UI Test" ""
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Installer Sections
Section "Dummy Section" SecDummy
SetOutPath "$INSTDIR"
;ADD YOUR OWN FILES HERE...
;Store installation folder
WriteRegStr HKCU "Software\Modern UI Test" "" $INSTDIR
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
FileOpen $0 "$INSTDIR\Uninstall.exe" w
Rename /REBOOTOK "$INSTDIR\Uninstall.exe" "$INSTDIR\Uninst.exe"
FileClose $0
SectionEnd
Function .onRebootFailed
MessageBox MB_OK "Reboot Failed"
FunctionEnd
;--------------------------------
;Descriptions
;Language strings
LangString DESC_SecDummy ${LANG_ENGLISH} "A test section."
;Assign language strings to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
Section "Uninstall"
;ADD YOUR OWN FILES HERE...
Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"
DeleteRegKey /ifempty HKCU "Software\Modern UI Test"
SectionEnd
Executing this example from a wrapper you'll see that the reboot command does not actually failed, it is the wrapper which remains open thus prevents the system from reboot.
In your case the second installer as you call it which executes the 1st installer and remains open and waiting, does not allow the system to reboot.
sunlight112
6th February 2007 01:50 UTC
Thank Red Wine a lot,
I understand your idea.
I still have one question "how can I catch the handle of radio button on the finish page if user click on "REBOOT NOW" or "REBOOT LATER"?
I am trying to require user reboot the system before using my application.
Can I find another solution to reboot system???
Please help me!!!!
Red Wine
6th February 2007 05:14 UTC
I still have one question "how can I catch the handle of radio button on the finish page if user click on "REBOOT NOW" or "REBOOT LATER"?
You may try to catch if the windows shoutdown service is activated.
dandaman32
6th February 2007 05:26 UTC
I assume that what you mean is add code to your application that checks for the reboot and if it hasn't been performed then ask to do a reboot. I think the best way to do this would be to create a flag-file in the installation and have this file deleted on reboot:
Section
FileOpen $0 $INSTDIR\rebootflag w
Delete /rebootok $INSTDIR\rebootflag ; this will not be deleted until the reboot because it is currently opened
FileClose $0
SectionEnd
In your application just check for the file rebootflag, and prompt for a reboot if it exists.
-dandaman32
Red Wine
6th February 2007 12:55 UTC
Just discovered a plugin at wiki that might be useful for your case,
http://nsis.sourceforge.net/ShutdownAllow_plug-in