silent.nsi 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # This example shows how to handle silent installers.
  2. # In short, you need IfSilent and the /SD switch for MessageBox to make your installer
  3. # really silent when the /S switch is used.
  4. Name "Silent"
  5. OutFile "silent.exe"
  6. RequestExecutionLevel user
  7. # uncomment the following line to make the installer silent by default.
  8. ; SilentInstall silent
  9. Function .onInit
  10. # `/SD IDYES' tells MessageBox to automatically choose IDYES if the installer is silent
  11. # in this case, the installer can only be silent if the user used the /S switch or if
  12. # you've uncommented line number 5
  13. MessageBox MB_YESNO|MB_ICONQUESTION "Would you like the installer to be silent from now on?" \
  14. /SD IDYES IDNO no IDYES yes
  15. # SetSilent can only be used in .onInit and doesn't work well along with `SetSilent silent'
  16. yes:
  17. SetSilent silent
  18. Goto done
  19. no:
  20. SetSilent normal
  21. done:
  22. FunctionEnd
  23. Section
  24. IfSilent 0 +2
  25. MessageBox MB_OK|MB_ICONINFORMATION 'This is a "silent" installer'
  26. # there is no need to use IfSilent for this one because the /SD switch takes care of that
  27. MessageBox MB_OK|MB_ICONINFORMATION "This is not a silent installer" /SD IDOK
  28. # when `SetOverwrite on' (which is the default) is used, the installer will show a message
  29. # if it can't open a file for writing. On silent installers, the ignore option will be
  30. # automatically selected. if `AllowSkipFiles off' (default is on) was used, there is no
  31. # ignore option and the cancel option will be automatically selected.
  32. # on is default
  33. ; AllowSkipFiles on
  34. # lock file
  35. FileOpen $0 $TEMP\silentOverwrite w
  36. # try to extract - will fail
  37. File /oname=$TEMP\silentOverwrite silent.nsi
  38. # unlcok
  39. FileClose $0
  40. # this will always show on silent installers because ignore is the option automatically
  41. # selected when a file can't be opened for writing on a silent installer
  42. MessageBox MB_OK|MB_ICONINFORMATION "This message box always shows if the installer is silent"
  43. AllowSkipFiles off
  44. # lock file
  45. FileOpen $0 $TEMP\silentOverwrite w
  46. # try to extract - will fail
  47. File /oname=$TEMP\silentOverwrite silent.nsi
  48. # unlcok
  49. FileClose $0
  50. SectionEnd