Chapter4.html 179 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns='http://www.w3.org/1999/xhtml'>
  4. <head>
  5. <title>Scripting Reference</title>
  6. <meta name="generator" content="Halibut v1.0 (NSIS Custom Build, SVN:r?) xhtml-backend" />
  7. <link rel="stylesheet" href="style.css" type='text/css' />
  8. </head>
  9. <body>
  10. <p><a href='Chapter3.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='Chapter5.html'>Next</a></p>
  11. <ul>
  12. <li><a class="btitle" href="Chapter4.html#"><b>Chapter 4: </b>Scripting Reference</a></li>
  13. <ul>
  14. <li><a href="Chapter4.html#fileformat">Script File Format</a></li>
  15. <li><a href="Chapter4.html#variables">Variables</a></li>
  16. <ul>
  17. <li><a href="Chapter4.html#varuser">User Variables</a></li>
  18. <li><a href="Chapter4.html#varother">Other Writable Variables</a></li>
  19. <li><a href="Chapter4.html#varconstant">Constants</a></li>
  20. <li><a href="Chapter4.html#varstrings">Constants Used in Strings</a></li>
  21. </ul>
  22. <li><a href="Chapter4.html#labels">Labels</a></li>
  23. <li><a href="Chapter4.html#jumps">Relative Jumps</a></li>
  24. <li><a href="Chapter4.html#pages">Pages</a></li>
  25. <ul>
  26. <li><a href="Chapter4.html#pageoreder">Ordering</a></li>
  27. <li><a href="Chapter4.html#pageoptions">Page Options</a></li>
  28. <li><a href="Chapter4.html#pagecallbacks_explain">Callbacks</a></li>
  29. <li><a href="Chapter4.html#page">Page</a></li>
  30. <li><a href="Chapter4.html#uninstpage">UninstPage</a></li>
  31. <li><a href="Chapter4.html#pageex">PageEx</a></li>
  32. <li><a href="Chapter4.html#pageexend">PageExEnd</a></li>
  33. <li><a href="Chapter4.html#pagecallbacks">PageCallbacks</a></li>
  34. </ul>
  35. <li><a href="Chapter4.html#sections">Sections</a></li>
  36. <ul>
  37. <li><a href="Chapter4.html#ssectioncommands">Section Commands</a></li>
  38. <li><a href="Chapter4.html#UninstallSection">Uninstall Section</a></li>
  39. </ul>
  40. <li><a href="Chapter4.html#functions">Functions</a></li>
  41. <ul>
  42. <li><a href="Chapter4.html#ffunctioncommands">Function Commands</a></li>
  43. <li><a href="Chapter4.html#callbacks">Callback Functions</a></li>
  44. </ul>
  45. <li><a href="Chapter4.html#instattribs">Installer Attributes</a></li>
  46. <ul>
  47. <li><a href="Chapter4.html#attribgen">General Attributes</a></li>
  48. <li><a href="Chapter4.html#flags">Compiler Flags</a></li>
  49. <li><a href="Chapter4.html#versioninfo">Version Information</a></li>
  50. </ul>
  51. <li><a href="Chapter4.html#instr">Instructions</a></li>
  52. <ul>
  53. <li><a href="Chapter4.html#basicinstructions">Basic Instructions</a></li>
  54. <li><a href="Chapter4.html#registry">Registry, INI, File Instructions</a></li>
  55. <li><a href="Chapter4.html#generalpurpose">General Purpose Instructions</a></li>
  56. <li><a href="Chapter4.html#flowcontrol">Flow Control Instructions</a></li>
  57. <li><a href="Chapter4.html#fileinst">File Instructions</a></li>
  58. <li><a href="Chapter4.html#uninst">Uninstaller Instructions</a></li>
  59. <li><a href="Chapter4.html#miscinst">Miscellaneous Instructions</a></li>
  60. <li><a href="Chapter4.html#stringinst">String Manipulation Instructions</a></li>
  61. <li><a href="Chapter4.html#stackinst">Stack Support</a></li>
  62. <li><a href="Chapter4.html#intinst">Integer Support</a></li>
  63. <li><a href="Chapter4.html#rebootinst">Reboot Instructions</a></li>
  64. <li><a href="Chapter4.html#installlog">Install Logging Instructions</a></li>
  65. <li><a href="Chapter4.html#secmanage">Section Management</a></li>
  66. <li><a href="Chapter4.html#ui">User Interface Instructions</a></li>
  67. <li><a href="Chapter4.html#langsinstructions">Multiple Languages Instructions</a></li>
  68. </ul>
  69. <li><a href="Chapter4.html#langs">Multiple Languages</a></li>
  70. <ul>
  71. <li><a href="Chapter4.html#langselection">Language Selection</a></li>
  72. <li><a href="Chapter4.html#langdll">LangDLL Plug-in</a></li>
  73. <li><a href="Chapter4.html#rtl">RTL Languages</a></li>
  74. </ul>
  75. <li><a href="Chapter4.html#plugindlls">Plug-in DLLs</a></li>
  76. <ul>
  77. <li><a href="Chapter4.html#usingplug">Using Plug-in Commands</a></li>
  78. <li><a href="Chapter4.html#calldiskplug">Calling plug-ins manually</a></li>
  79. </ul>
  80. <li><a href="Chapter4.html#silent">Silent Installers/Uninstallers</a></li>
  81. </ul>
  82. </ul>
  83. <a name="scriptref"></a><h1>Chapter 4: Scripting Reference</h1>
  84. <a name="fileformat"></a><h2>4.1 Script File Format</h2>
  85. <p>A NSIS Script File (.nsi) is just a text file with script code.</p>
  86. <p><b>Commands</b></p>
  87. <p>Commands lines are in the format 'command [parameters]'</p>
  88. <pre>File &quot;myfile&quot;
  89. </pre>
  90. <p><b>Comments</b></p>
  91. <p>Lines beginning with ; or # are comments. You can put comments after commands. You can also use C-style comments to comment one or more lines.</p>
  92. <pre>; Comment
  93. # Comment
  94. # Comment \
  95. Another comment line (see `Long commands` section below)
  96. /*
  97. Comment
  98. Comment
  99. */
  100. Name /* comment */ mysetup
  101. File &quot;myfile&quot; ; Comment
  102. </pre>
  103. <p>If you want a parameter to start with ; or # put it in quotes.</p>
  104. <p><b>Plug-ins</b></p>
  105. <p>To call a plug-in, use 'plugin::command [parameters]'. For more info see <a href="Chapter4.html#plugindlls">Plug-in DLLs</a>.</p>
  106. <pre>nsExec::Exec &quot;myfile&quot;
  107. </pre>
  108. <p><b>Numbers</b></p>
  109. <p>For parameters that are treated as numbers, use decimal (the number) or hexadecimal (with 0x prepended to it, i.e. 0x12345AB), or octal (numbers beginning with a 0 and no x).</p>
  110. <p>Colors should be set in hexadecimal RGB format, like HTML but without the #.</p>
  111. <pre>IntCmp 1 0x1 lbl_equal
  112. SetCtlColors $HWND CCCCCC
  113. </pre>
  114. <p><b>Strings</b></p>
  115. <p>To represent strings that have spaces, use quotes:</p>
  116. <pre>MessageBox MB_OK &quot;Hi there!&quot;
  117. </pre>
  118. <p>Quotes only have the property of containing a parameter if they surround the rest of the parameter. They can be either single quotes, double quotes, or the backward single quote.</p>
  119. <p>You can escape quotes using $\:</p>
  120. <pre>MessageBox MB_OK &quot;I'll be happy&quot; ; this one puts a ' inside a string
  121. MessageBox MB_OK 'And he said to me &quot;Hi there!&quot;' ; this one puts a &quot; inside a string
  122. MessageBox MB_OK `And he said to me &quot;I'll be happy!&quot;` ; this one puts both ' and &quot;s inside a string
  123. MessageBox MB_OK &quot;$\&quot;A quote from a wise man$\&quot; said the wise man&quot; ; this one shows escaping of quotes
  124. </pre>
  125. <p>It is also possible to put newlines, tabs etc. in a string using $\r, $\n, $\t etc. <a href="Chapter4.html#varstrings">More information...</a></p>
  126. <p><b>Variables</b></p>
  127. <p>Variables start with $. User variables must be declared.</p>
  128. <pre>Var MYVAR
  129. StrCpy $MYVAR &quot;myvalue&quot;
  130. </pre>
  131. <p><a href="Chapter4.html#variables">More information...</a></p>
  132. <p><b>Long commands</b></p>
  133. <p>To extend a command over multiple lines, use a backslash (\) at the end of the line. The next line will effectively be concatenated to the end of it. For example:</p>
  134. <pre>CreateShortcut &quot;$SMPROGRAMS\NSIS\ZIP2EXE project workspace.lnk&quot; \
  135. &quot;$INSTDIR\source\zip2exe\zip2exe.dsw&quot;
  136. MessageBox MB_YESNO|MB_ICONQUESTION \
  137. &quot;Do you want to remove all files in the folder? \
  138. (If you have anything you created that you want \
  139. to keep, click No)&quot; \
  140. IDNO NoRemoveLabel
  141. </pre>
  142. <p>Line extension for long commands works for comments as well. It can be a bit confusing, so it should be avoided.</p>
  143. <pre># A comment \
  144. still a comment here...
  145. </pre>
  146. <p><b>Configuration file</b></p>
  147. <p>If a file named &quot;nsisconf.nsh&quot; in the config directory exists, it will be included by default before any scripts (unless the /NOCONFIG command line parameter is used). The config directory on Windows is the same directory as makensis.exe is in. On other platforms this is set at install time and defaults to $PREFIX/etc/. You can alter this at runtime, see <a href="Chapter3.html#usageenvironment">section 3.1.3</a> for more information.</p>
  148. <a name="variables"></a><h2>4.2 Variables</h2>
  149. <p>All variables are global and can be used in Sections or Functions. Note that by default, variables are limited to 1024 characters. To extend this limit, <a href="AppendixG.html#build">build NSIS</a> with a bigger value of the NSIS_MAX_STRLEN build setting or use the <a href="http://nsis.sourceforge.net/download/specialbuilds/">special build</a>.</p>
  150. <a name="varuser"></a><h3>4.2.1 User Variables</h3>
  151. <p><em>$VARNAME</em></p>
  152. <p>User variables must be declared with the <a href="Chapter4.html#var">Var</a> command. You can use these variables to store values, work with string manipulation etc.</p>
  153. <a name="var"></a><h4>4.2.1.1 Var</h4>
  154. <pre>[/GLOBAL] var_name
  155. </pre>
  156. <p>Declare a user variable. Allowed characters for variables names: [a-z][A-Z][0-9] and '_'. All defined variables are global, even if defined in a section or a function. To make this clear, variables defined in a section or a function must use the /GLOBAL flag. The /GLOBAL flag is not required outside of sections and functions.</p>
  157. <pre>Var example
  158. Function testVar
  159. Var /GLOBAL example2
  160. StrCpy $example &quot;example value&quot;
  161. StrCpy $example2 &quot;another example value&quot;
  162. FunctionEnd
  163. </pre>
  164. <a name="varother"></a><h3>4.2.2 Other Writable Variables</h3>
  165. <p><em>$0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $R0, $R1, $R2, $R3, $R4, $R5, $R6, $R7, $R8, $R9</em></p>
  166. <p>Registers. These variables can be used just like user variables, but are usually used in shared functions or macros. You don't have to declare these variables so you won't get any name conflicts when using them in shared code. When using these variables in shared code it's recommended that you use the stack to save and restore their original values. These variables can also be used for communication with plug-ins because they can be read and written by the plug-in DLLs.</p>
  167. <p><em>$INSTDIR</em></p>
  168. <p>The installation directory ($INSTDIR is modifiable using <a href="Chapter4.html#StrCpy">StrCpy</a>, <a href="Chapter4.html#readregstr">ReadRegStr</a>, <a href="Chapter4.html#readinistr">ReadINIStr</a>, etc. - This could be used, for example, in the <a href="Chapter4.html#oninit">.onInit</a> function to do a more advanced detection of install location).</p>
  169. <p>Note that in uninstaller code, $INSTDIR contains the directory where the uninstaller lies. It does <b>not</b> necessarily contain the same value it contained in the installer. For example, if you write the uninstaller to $WINDIR and the user doesn't move it, $INSTDIR will be $WINDIR in the uninstaller. If you write the uninstaller to another location, you should keep the installer's $INSTDIR in the registry or an alternative storing facility and read it in the uninstaller.</p>
  170. <p><em>$OUTDIR</em></p>
  171. <p>The current output directory (set implicitly via <a href="Chapter4.html#setoutpath">SetOutPath</a> or explicitly via <a href="Chapter4.html#StrCpy">StrCpy</a>, <a href="Chapter4.html#readregstr">ReadRegStr</a>, <a href="Chapter4.html#readinistr">ReadINIStr</a>, etc)</p>
  172. <p><em>$CMDLINE</em></p>
  173. <p>The command line of the installer. The format of the command line can be one of the following:</p>
  174. <ul>
  175. <li>&quot;full\path to\installer.exe&quot; PARAMETER PARAMETER PARAMETER</li><li>installer.exe PARAMETER PARAMETER PARAMETER</li><li>For parsing out the PARAMETER portion, see <a href="AppendixE.html#getparameters">GetParameters</a>. If /D= is specified on the command line (to override the install directory) it won't show up in $CMDLINE.</li></ul>
  176. <p><em>$LANGUAGE</em></p>
  177. <p>The identifier of the language that is currently used. For example, English is 1033. You can only change this variable in <a href="Chapter4.html#oninit">.onInit</a>.</p>
  178. <a name="varconstant"></a><h3>4.2.3 Constants</h3>
  179. <p>Constants can also be used in the <a href="Chapter4.html#ainstalldir">InstallDir</a> attribute.</p>
  180. <p>Note that some of the new constants will not work on every OS. For example, $CDBURN_AREA will only work on Windows XP and above. If it's used on Windows 98, it'll be empty. Unless mentioned otherwise, a constant should be available on every OS.</p>
  181. <p><em>$PROGRAMFILES</em>, <em>$PROGRAMFILES32</em>, <em>$PROGRAMFILES64</em></p>
  182. <p>The program files directory (usually <code>C:\Program Files</code> but detected at runtime). On Windows x64, $PROGRAMFILES and $PROGRAMFILES32 point to <code>C:\Program Files (x86)</code> while $PROGRAMFILES64 points to <code>C:\Program Files</code>. Use $PROGRAMFILES64 when installing x64 applications.</p>
  183. <p><em>$COMMONFILES</em>, <em>$COMMONFILES32</em>, <em>$COMMONFILES64</em></p>
  184. <p>The common files directory. This is a directory for components that are shared across applications (usually <code>C:\Program Files\Common Files</code> but detected at runtime). On Windows x64, $COMMONFILES and $COMMONFILES32 point to <code>C:\Program Files (x86)\Common Files</code> while $COMMONFILES64 points to <code>C:\Program Files\Common Files</code>. Use $COMMONFILES64 when installing x64 applications.</p>
  185. <p><em>$DESKTOP</em></p>
  186. <p>The Windows desktop directory. The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  187. <p><em>$EXEDIR</em></p>
  188. <p>The directory containing the installer executable (technically this is a variable and you can modify it, but it is probably not a good idea).</p>
  189. <p><em>$EXEFILE</em></p>
  190. <p>The base name of the installer executable.</p>
  191. <p><em>$EXEPATH</em></p>
  192. <p>The full path of the installer executable.</p>
  193. <p><em>${NSISDIR}</em></p>
  194. <p>A symbol that contains the path where NSIS is installed. Useful if you want to reference resources that are in NSIS directory e.g. Icons, UIs etc.</p>
  195. <p>When compiled with support for keeping makensis and the data in the same place (the default on Windows), it is in the same place as makensis, on other platforms it is set at compile time (See the INSTALL file for info). In both instances you can modify it at runtime by setting the NSISDIR environment variable. See <a href="Chapter3.html#usageenvironment">section 3.1.3</a> for more info.</p>
  196. <p><em>$WINDIR</em></p>
  197. <p>The Windows directory (usually <code>C:\Windows</code> or <code>C:\WinNT</code> but detected at runtime).</p>
  198. <p><em>$SYSDIR</em></p>
  199. <p>The Windows system directory (usually <code>C:\Windows\System</code> or <code>C:\WinNT\System32</code> but detected at runtime).</p>
  200. <p><em>$TEMP</em></p>
  201. <p>The temporary directory.</p>
  202. <p><em>$STARTMENU</em></p>
  203. <p>The start menu folder (useful for adding start menu items using <a href="Chapter4.html#createshortcut">CreateShortcut</a>). The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  204. <p><em>$SMPROGRAMS</em></p>
  205. <p>The start menu programs folder (use this whenever you want $STARTMENU\Programs). The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  206. <p><em>$SMSTARTUP</em></p>
  207. <p>The start menu programs / startup folder. The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  208. <p><em>$QUICKLAUNCH</em></p>
  209. <p>The quick launch folder for IE4 active desktop and above. If quick launch is not available it simply returns the same as $TEMP.</p>
  210. <p><em>$DOCUMENTS</em></p>
  211. <p>The documents directory. A typical path for the current user is <code>C:\Documents and Settings\Foo\My Documents</code>. The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  212. <p>This constant is not available on Windows 95 unless Internet Explorer 4 is installed.</p>
  213. <p><em>$SENDTO</em></p>
  214. <p>The directory that contains Send To menu shortcut items.</p>
  215. <p><em>$RECENT</em></p>
  216. <p>The directory that contains shortcuts to the user's recently used documents.</p>
  217. <p><em>$FAVORITES</em></p>
  218. <p>The directory that contains shortcuts to the user's favorite websites, documents, etc. The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  219. <p>This constant is not available on Windows 95 unless Internet Explorer 4 is installed.</p>
  220. <p><em>$MUSIC</em></p>
  221. <p>The user's music files directory. The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  222. <p>This constant is available on Windows XP, ME and above.</p>
  223. <p><em>$PICTURES</em></p>
  224. <p>The user's picture files directory. The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  225. <p>This constant is available on Windows 2000, XP, ME and above.</p>
  226. <p><em>$VIDEOS</em></p>
  227. <p>The user's video files directory. The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  228. <p>This constant is available on Windows XP, ME and above.</p>
  229. <p><em>$NETHOOD</em></p>
  230. <p>The directory that contains link objects that may exist in the My Network Places/Network Neighborhood folder.</p>
  231. <p>This constant is not available on Windows 95 unless Internet Explorer 4 with Active Desktop is installed.</p>
  232. <p><em>$FONTS</em></p>
  233. <p>The system's fonts directory.</p>
  234. <p><em>$TEMPLATES</em></p>
  235. <p>The document templates directory. The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  236. <p><em>$APPDATA</em></p>
  237. <p>The application data directory. Detection of the current user path requires Internet Explorer 4 and above. Detection of the all users path requires Internet Explorer 5 and above. The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  238. <p>This constant is not available on Windows 95 unless Internet Explorer 4 with Active Desktop is installed.</p>
  239. <p><em>$LOCALAPPDATA</em></p>
  240. <p>The local (non-roaming) application data directory.</p>
  241. <p>This constant is available on Windows 2000 and above.</p>
  242. <p><em>$PRINTHOOD</em></p>
  243. <p>The directory that contains link objects that may exist in the Printers folder.</p>
  244. <p>This constant is not available on Windows 95 and Windows 98.</p>
  245. <p><em>$INTERNET_CACHE</em></p>
  246. <p>Internet Explorer's temporary internet files directory.</p>
  247. <p>This constant is not available on Windows 95 nor Windows NT 4 unless Internet Explorer 4 with Active Desktop is installed.</p>
  248. <p><em>$COOKIES</em></p>
  249. <p>Internet Explorer's cookies directory.</p>
  250. <p>This constant is not available on Windows 95 nor Windows NT 4 unless Internet Explorer 4 with Active Desktop is installed.</p>
  251. <p><em>$HISTORY</em></p>
  252. <p>Internet Explorer's history directory.</p>
  253. <p>This constant is not available on Windows 95 nor Windows NT 4 unless Internet Explorer 4 with Active Desktop is installed.</p>
  254. <p><em>$PROFILE</em></p>
  255. <p>The user's profile directory. A typical path is <code>C:\Documents and Settings\Foo</code>.</p>
  256. <p>This constant is available on Windows 2000 and above.</p>
  257. <p><em>$ADMINTOOLS</em></p>
  258. <p>A directory where administrative tools are kept. The context of this constant (All Users or Current user) depends on the <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> setting. The default is the current user.</p>
  259. <p>This constant is available on Windows 2000, ME and above.</p>
  260. <p><em>$RESOURCES</em></p>
  261. <p>The resources directory that stores themes and other Windows resources (usually <code>$WINDIR\Resources</code> but detected at runtime).</p>
  262. <p>This constant is available on Windows XP and above.</p>
  263. <p><em>$RESOURCES_LOCALIZED</em></p>
  264. <p>The localized resources directory that stores themes and other Windows resources (usually <code>$WINDIR\Resources\1033</code> but detected at runtime).</p>
  265. <p>This constant is available on Windows XP and above.</p>
  266. <p><em>$CDBURN_AREA</em></p>
  267. <p>A directory where files awaiting to be burned to CD are stored.</p>
  268. <p>This constant is available on Windows XP and above.</p>
  269. <p><em>$HWNDPARENT</em></p>
  270. <p>HWND of the main window (in decimal).</p>
  271. <p><em>$PLUGINSDIR</em></p>
  272. <p>The path to a temporary folder created upon the first usage of a plug-in or a call to <a href="Chapter4.html#initpluginsdir">InitPluginsDir</a>. This folder is automatically deleted when the installer exits. This makes this folder the ideal folder to hold INI files for <a href="../Docs/InstallOptions/Readme.html">InstallOptions</a>, bitmaps for the splash plug-in, or any other file that a plug-in needs to work.</p>
  273. <a name="varstrings"></a><h3>4.2.4 Constants Used in Strings</h3>
  274. <p><em>$$</em></p>
  275. <p>Use to represent $.</p>
  276. <p><em>$\r</em></p>
  277. <p>Use to represent a carriage return (\r).</p>
  278. <p><em>$\n</em></p>
  279. <p>Use to represent a newline (\n).</p>
  280. <p><em>$\t</em></p>
  281. <p>Use to represent a tab (\t).</p>
  282. <a name="labels"></a><h2>4.3 Labels</h2>
  283. <p>Labels are the targets of <a href="Chapter4.html#goto">Goto</a> instructions and the various branching instructions (such as <a href="Chapter4.html#iferrors">IfErrors</a>, <a href="Chapter4.html#messagebox">MessageBox</a>, <a href="Chapter4.html#iffileexists">IfFileExists</a>, and <a href="Chapter4.html#strcmp">StrCmp</a>). Labels must be within a <a href="Chapter4.html#ssection">Section</a> or a <a href="Chapter4.html#ffunction">Function</a>. Labels are local in scope, meaning they are only accessible from within the <a href="Chapter4.html#ssection">Section</a> or <a href="Chapter4.html#ffunction">Function</a> that they reside in. To declare a label, simply use:</p>
  284. <p><em>MyLabel:</em></p>
  285. <p>Labels cannot begin with a -, +, !, $, or 0-9. When specifying labels for the various instructions that require them, remember that both an empty string (&quot;&quot;) and 0 both represent the next instruction (meaning no <a href="Chapter4.html#goto">Goto</a> will occur). Labels beginning with a period (.) are global, meaning you can jump to them from any function or section (though you cannot jump to an uninstall global label from the installer, and vice versa).</p>
  286. <a name="jumps"></a><h2>4.4 Relative Jumps</h2>
  287. <p>Unlike labels, relative jumps are, as the name suggests, relative to the place they are called from. You can use relative jumps wherever you can use labels. Relative jumps are marked by numbers. +1 jumps to the next instruction (the default advancement), +2 will skip one instruction and go to the second instruction from the current instruction, -2 will jump two instructions backward, and +10 will skip 9 instructions, jumping to the tenth instruction from the current instruction.</p>
  288. <p>A instruction is every command that is executed at run-time, when the installer is running. <a href="Chapter4.html#messagebox">MessageBox</a>, <a href="Chapter4.html#goto">Goto</a>, <a href="Chapter4.html#getdllversion">GetDLLVersion</a>, <a href="Chapter4.html#FileRead">FileRead</a>, <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> are all instructions. <a href="Chapter4.html#saddsize">AddSize</a>, <a href="Chapter4.html#ssection">Section</a>, <a href="Chapter4.html#ssectiongroup">SectionGroup</a>, <a href="Chapter4.html#ssectionend">SectionEnd</a>, <a href="Chapter4.html#asetoverwrite">SetOverwrite</a> (and everything under <a href="Chapter4.html#flags">Compiler Flags</a>), <a href="Chapter4.html#aname">Name</a>, <a href="Chapter4.html#asetfont">SetFont</a>, <a href="Chapter4.html#langstring">LangString</a>, are not instructions because they are executed at compile time.</p>
  289. <p>Examples:</p>
  290. <pre> Goto +2
  291. MessageBox MB_OK &quot;You will never ever see this message box&quot;
  292. MessageBox MB_OK &quot;The last message was skipped, this one should be shown&quot;
  293. </pre>
  294. <pre> Goto +4
  295. MessageBox MB_OK &quot;The following message will be skipped&quot;
  296. Goto +3
  297. MessageBox MB_OK &quot;You will never ever see this message box&quot;
  298. Goto -3
  299. MessageBox MB_OK &quot;Done&quot;
  300. </pre>
  301. <p>Note that <a href="Chapter5.html#insertmacro">macro insertion</a> is not considered as one instruction when it comes to relative jumps. The macro is expanded before relative jumps are applied, and so relative jumps can jump into code inside an inserted macro. The following code, for example, will not skip the macro. It will show a message box.</p>
  302. <pre>!macro relative_jump_test
  303. MessageBox MB_OK &quot;first macro line&quot;
  304. MessageBox MB_OK &quot;second macro line&quot;
  305. !macroend
  306. Goto +2
  307. !insertmacro relative_jump_test
  308. </pre>
  309. <a name="pages"></a><h2>4.5 Pages</h2>
  310. <p>Each (non-silent) NSIS installer has a set of pages. Each page can be a NSIS built-in page or a custom page created by a user's function (with <a href="../Docs/nsDialogs/Readme.html">nsDialogs</a> or <a href="../Docs/InstallOptions/Readme.html">InstallOptions</a> for example).</p>
  311. <p>The script controls the page order, appearance, and behavior. You can skip pages, paint them white, force the user to stay in a certain page until a certain condition is met, show a readme page, show custom designed pages for input and more. In this section you will learn how to do all of the above.</p>
  312. <p>There are two basic commands regarding pages, <a href="Chapter4.html#page">Page</a> and <a href="Chapter4.html#uninstpage">UninstPage</a>. The first adds a page to the installer, the second adds a page to the uninstaller. On top of those two there is the <a href="Chapter4.html#pageex">PageEx</a> command which allows you to add a page to either one and with greater amount of options. <a href="Chapter4.html#pageex">PageEx</a> allows you to set options to the specific page you are adding instead of using the default that's set outside of <a href="Chapter4.html#pageex">PageEx</a>.</p>
  313. <a name="pageoreder"></a><h3>4.5.1 Ordering</h3>
  314. <p>The page order is set simply by the order <a href="Chapter4.html#page">Page</a>, <a href="Chapter4.html#uninstpage">UninstPage</a> and <a href="Chapter4.html#pageex">PageEx</a> appear in the script. For example:</p>
  315. <pre> Page license
  316. Page components
  317. Page directory
  318. Page instfiles
  319. UninstPage uninstConfirm
  320. UninstPage instfiles
  321. </pre>
  322. <p>This code will tell NSIS to first show the license page, then the components selection page, then the directory selection page and finally the install log where sections are executed. The uninstaller will first show the uninstall confirmation page and then the uninstallation log.</p>
  323. <p>You can specify the same page type more than once.</p>
  324. <p>For backwards compatibility with old NSIS scripts, the following installer pages will be added if no installer page commands are used: license (if <a href="Chapter4.html#alicensetext">LicenseText</a> and <a href="Chapter4.html#alicensedata">LicenseData</a> were specified), components (if <a href="Chapter4.html#acomponenttext">ComponentText</a> was specified and there is more than one visible section), directory (if <a href="Chapter4.html#adirtext">DirText</a> was specified) and instfiles. When there are no uninstaller page commands the following uninstaller pages will be added: uninstall confirmation page (if <a href="Chapter4.html#auninstalltext">UninstallText</a> was specified) and instfiles. This method is deprecated, converting scripts to use page commands is highly recommended because you can use the new standard language strings.</p>
  325. <a name="pageoptions"></a><h3>4.5.2 Page Options</h3>
  326. <p>Each page has its unique set of data that defines how it will look and act. This section describes what data each type of page uses and how you can set it. <a href="Chapter4.html#pagecallbacks_explain">Callback functions</a> are described below and are not dealt with in this section.</p>
  327. <p>The list below lists the commands that affect a certain page type. Unless otherwise mentioned, these commands can be used both inside and outside of a <a href="Chapter4.html#pageex">PageEx</a> block. If used inside a <a href="Chapter4.html#pageex">PageEx</a> block they will only affect the current page being set by PageEx, otherwise they will set the default for all other pages.</p>
  328. <p><em>License page</em></p>
  329. <ul>
  330. <li><a href="Chapter4.html#alicensetext">LicenseText</a></li><li><a href="Chapter4.html#alicensedata">LicenseData</a></li><li><a href="Chapter4.html#alicenseforceselection">LicenseForceSelection</a></li></ul>
  331. <p><em>Components selection page</em></p>
  332. <ul>
  333. <li><a href="Chapter4.html#acomponenttext">ComponentText</a></li></ul>
  334. <p><em>Directory selection page</em></p>
  335. <ul>
  336. <li><a href="Chapter4.html#adirtext">DirText</a></li><li><a href="Chapter4.html#adirvar">DirVar</a> (can only be used in <a href="Chapter4.html#pageex">PageEx</a>)</li><li><a href="Chapter4.html#adirverify">DirVerify</a></li></ul>
  337. <p><em>Un/Installation log page</em></p>
  338. <ul>
  339. <li><a href="Chapter4.html#adetailsbuttontext">DetailsButtonText</a></li><li><a href="Chapter4.html#acompletedtext">CompletedText</a></li></ul>
  340. <p><em>Uninstall confirmation page</em></p>
  341. <ul>
  342. <li><a href="Chapter4.html#adirvar">DirVar</a> (can only be used in <a href="Chapter4.html#pageex">PageEx</a>)</li><li><a href="Chapter4.html#auninstalltext">UninstallText</a></li></ul>
  343. <p>Use <a href="Chapter4.html#acaption">Caption</a> to set the page caption.</p>
  344. <a name="pagecallbacks_explain"></a><h3>4.5.3 Callbacks</h3>
  345. <p>Each built-in page has three callback functions: the pre-function, the show function and the leave-function. The pre-function is called right before the page is created, the show-function is called right after it has been created but before it is shown and the leave-function is called right after the user has pressed the next button (before actually leaving the page).</p>
  346. <ul>
  347. <li>The pre-function allows you to skip the page using <a href="Chapter4.html#abort">Abort</a>.</li><li>The show-function allows you to tweak the page's user interface with <a href="Chapter4.html#createfont">CreateFont</a>, <a href="Chapter4.html#setctlcolors">SetCtlColors</a>, <a href="Chapter4.html#sendmessage">SendMessage</a> etc.</li><li>The leave-function allows you to force the user to stay on the current page using <a href="Chapter4.html#abort">Abort</a>.</li></ul>
  348. <p>A custom page only has two callback functions, one that creates it which is mandatory, and one leave-function that acts just like the leave-function for built-in pages.</p>
  349. <p>Examples:</p>
  350. <pre> Page license skipLicense &quot;&quot; stayInLicense
  351. Page custom customPage &quot;&quot; &quot;: custom page&quot;
  352. Page instfiles
  353. Function skipLicense
  354. MessageBox MB_YESNO &quot;Do you want to skip the license page?&quot; IDNO no
  355. Abort
  356. no:
  357. FunctionEnd
  358. Function stayInLicense
  359. MessageBox MB_YESNO &quot;Do you want to stay in the license page?&quot; IDNO no
  360. Abort
  361. no:
  362. FunctionEnd
  363. Function customPage
  364. GetTempFileName $R0
  365. File /oname=$R0 customPage.ini
  366. InstallOptions::dialog $R0
  367. Pop $R1
  368. StrCmp $R1 &quot;cancel&quot; done
  369. StrCmp $R1 &quot;back&quot; done
  370. StrCmp $R1 &quot;success&quot; done
  371. error: MessageBox MB_OK|MB_ICONSTOP &quot;InstallOptions error:$\r$\n$R1&quot;
  372. done:
  373. FunctionEnd
  374. </pre>
  375. <a name="page"></a><h3>4.5.4 Page</h3>
  376. <pre>custom [creator_function] [leave_function] [caption] [/ENABLECANCEL]
  377. OR
  378. internal_page_type [pre_function] [show_function] [leave_function] [/ENABLECANCEL]
  379. </pre>
  380. <p>Adds an installer page. See the above sections for more information about built-in versus custom pages and about callback functions.</p>
  381. <p><em>internal_page_type</em> can be:</p>
  382. <ul>
  383. <li><em>license</em> - license page</li><li><em>components</em> - components selection page</li><li><em>directory</em> - installation directory selection page</li><li><em>instfiles</em> - installation page where the sections are executed</li><li><em>uninstConfirm</em> - uninstall confirmation page</li></ul>
  384. <p>The last page of the installer has its cancel button disabled to prevent confusion. To enable it anyway, use <em>/ENABLECANCEL</em>.</p>
  385. <a name="uninstpage"></a><h3>4.5.5 UninstPage</h3>
  386. <pre>custom [creator_function] [leave_function] [caption] [/ENABLECANCEL]
  387. OR
  388. internal_page_type [pre_function] [show_function] [leave_function] [/ENABLECANCEL]
  389. </pre>
  390. <p>Adds an uninstaller page. See the above sections for more information about built-in versus custom pages and about callback functions.</p>
  391. <p>See <a href="Chapter4.html#page">Page</a> for possible values of <em>internal_page_type</em>.</p>
  392. <a name="pageex"></a><h3>4.5.6 PageEx</h3>
  393. <pre>[un.](custom|uninstConfirm|license|components|directory|instfiles)
  394. </pre>
  395. <p>Adds an installer page or an uninstaller page if the un. prefix was used. Every PageEx must have a matching <a href="Chapter4.html#pageexend">PageExEnd</a>. In a PageEx block you can set options that are specific to this page and will not be used for other pages. Options that are not set will revert to what was set outside the PageEx block or the default if nothing was set. To set the sub-caption for a page use <a href="Chapter4.html#acaption">Caption</a> or <a href="Chapter4.html#asubcaption">SubCaption</a> to set the default. To set the callback functions for a page set with PageEx use <a href="Chapter4.html#pagecallbacks">PageCallbacks</a>. See the above sections for more information about built-in versus custom pages.</p>
  396. <p>Example usage:</p>
  397. <pre> PageEx license
  398. LicenseText &quot;Readme&quot;
  399. LicenseData readme.rtf
  400. PageExEnd
  401. PageEx license
  402. LicenseData license.txt
  403. LicenseForceSelection checkbox
  404. PageExEnd
  405. </pre>
  406. <a name="pageexend"></a><h3>4.5.7 PageExEnd</h3>
  407. <p>Ends a <a href="Chapter4.html#pageex">PageEx</a> block.</p>
  408. <a name="pagecallbacks"></a><h3>4.5.8 PageCallbacks</h3>
  409. <pre>([creator_function] [leave_function]) | ([pre_function] [show_function] [leave_function])
  410. </pre>
  411. <p>Sets the callback functions for a page defined using <a href="Chapter4.html#pageex">PageEx</a>. Can only be used inside a <a href="Chapter4.html#pageex">PageEx</a> block. See the above sections for more information about callback functions.</p>
  412. <pre>PageEx license
  413. PageCallbacks licensePre licenseShow licenseLeave
  414. PageExEnd
  415. </pre>
  416. <a name="sections"></a><h2>4.6 Sections</h2>
  417. <p>Each NSIS installer contains one or more sections. Each of these sections are created, modified, and ended with the following commands.</p>
  418. <ul>
  419. <li>Each section contains zero or more instructions.</li><li>Sections are executed in order by the resulting installer, and if a component page is used, the user will have the option of disabling/enabling each visible section.</li><li>If a section's name is 'Uninstall' or is prefixed with 'un.', it's an uninstaller section.</li></ul>
  420. <a name="ssectioncommands"></a><h3>4.6.1 Section Commands</h3>
  421. <a name="saddsize"></a><h4>4.6.1.1 AddSize</h4>
  422. <pre>size_kb
  423. </pre>
  424. <p>Tells the installer that the current section needs an additional &quot;size_kb&quot; kilobytes of disk space. Only valid within a section (will have no effect outside of a section or in a function).</p>
  425. <pre>Section
  426. AddSize 500
  427. SectionEnd
  428. </pre>
  429. <a name="ssection"></a><h4>4.6.1.2 Section</h4>
  430. <pre>[/o] [([!]|[-])section_name] [section_index_output]
  431. </pre>
  432. <p>Begins and opens a new section. If section_name is empty, omitted, or begins with a -, then it is a hidden section and the user will not have the option of disabling it. If the section name is 'Uninstall' or is prefixed with 'un.', then it is a an uninstaller section. If <em>section_index_output</em> is specified, the parameter will be <a href="Chapter5.html#define">!defined</a> with the section index (can be used with <a href="Chapter4.html#sectionsettext">SectionSetText</a> etc). If the section name begins with a !, the section will be displayed as bold. If the /o switch is specified, the section will be unselected by default.</p>
  433. <pre>Section &quot;-hidden section&quot;
  434. SectionEnd
  435. Section # hidden section
  436. SectionEnd
  437. Section &quot;!bold section&quot;
  438. SectionEnd
  439. Section /o &quot;optional&quot;
  440. SectionEnd
  441. Section &quot;install something&quot; SEC_IDX
  442. SectionEnd
  443. </pre>
  444. <p>To access the section index, curly brackets must be used and the code must be located below the section in the script.</p>
  445. <pre>Section test1 sec1_id
  446. SectionEnd
  447. Section test2 sec2_id
  448. SectionEnd
  449. Function .onInit
  450. SectionGetText ${sec2_id} $0
  451. MessageBox MB_OK &quot;name of ${sec2_id}:$\n$0&quot; # will correctly display 'name of 1: test2'
  452. FunctionEnd
  453. </pre>
  454. <pre>Function .onInit
  455. SectionGetText ${sec2_id} $0
  456. MessageBox MB_OK &quot;name of ${sec2_id}:$\n$0&quot; # will incorrectly display 'name of ${sec2_id}: test1'
  457. # plus a warning stating:
  458. # unknown variable/constant &quot;{sec2_id}&quot; detected, ignoring
  459. FunctionEnd
  460. Section test1 sec1_id
  461. SectionEnd
  462. Section test2 sec2_id
  463. SectionEnd
  464. </pre>
  465. <a name="ssectionend"></a><h4>4.6.1.3 SectionEnd</h4>
  466. <p>This command closes the current open section.</p>
  467. <a name="ssectionin"></a><h4>4.6.1.4 SectionIn</h4>
  468. <pre>insttype_index [insttype_index] [RO]
  469. </pre>
  470. <p>This command specifies which install types (see <a href="Chapter4.html#ainsttype">InstType</a>) the current section defaults to the enabled state in. Multiple <a href="Chapter4.html#ssectionin">SectionIn</a> commands can be specified (they are combined). If you specify RO as a parameter, then the section will be read-only, meaning the user won't be able to change its state. The first install type defined using <a href="Chapter4.html#ainsttype">InstType</a> is indexed 1, the next 2 and so on.</p>
  471. <pre>InstType &quot;full&quot;
  472. InstType &quot;minimal&quot;
  473. Section &quot;a section&quot;
  474. SectionIn 1 2
  475. SectionEnd
  476. Section &quot;another section&quot;
  477. SectionIn 1
  478. SectionEnd
  479. </pre>
  480. <a name="ssectiongroup"></a><h4>4.6.1.5 SectionGroup</h4>
  481. <pre>[/e] section_group_name [index_output]
  482. </pre>
  483. <p>This command inserts a section group. The section group must be closed with <a href="Chapter4.html#ssectiongroupend">SectionGroupEnd</a>, and should contain 1 or more sections. If the section group name begins with a !, its name will be displayed with a bold font. If /e is present, the section group will be expanded by default. If <em>index_output</em> is specified, the parameter will be !defined with the section index (can be used with <a href="Chapter4.html#sectionsettext">SectionSetText</a> etc). If the name is prefixed with 'un.' the section group is an uninstaller section group.</p>
  484. <pre>SectionGroup &quot;some stuff&quot;
  485. Section &quot;a section&quot;
  486. SectionEnd
  487. Section &quot;another section&quot;
  488. SectionEnd
  489. SectionGroupEnd
  490. </pre>
  491. <a name="ssectiongroupend"></a><h4>4.6.1.6 SectionGroupEnd</h4>
  492. <p>Closes a section group opened with <a href="Chapter4.html#ssectiongroup">SectionGroup</a>.</p>
  493. <a name="UninstallSection"></a><h3>4.6.2 Uninstall Section</h3>
  494. <p>A special <a href="Chapter4.html#ssection">Section</a> named 'Uninstall' must be created in order to generate an uninstaller. This section should remove all files, registry keys etc etc that were installed by the installer, from the system. Here is an example of a simple uninstall section:</p>
  495. <pre>Section &quot;Uninstall&quot;
  496. Delete $INSTDIR\Uninst.exe ; delete self (see explanation below why this works)
  497. Delete $INSTDIR\myApp.exe
  498. RMDir $INSTDIR
  499. DeleteRegKey HKLM SOFTWARE\myApp
  500. SectionEnd
  501. </pre>
  502. <p>The first <a href="Chapter4.html#delete">Delete</a> instruction works (deleting the uninstaller), because the uninstaller is transparently copied to the system temporary directory for the uninstall.</p>
  503. <p>Note that in uninstaller code, $INSTDIR contains the directory where the uninstaller lies. It does <b>not</b> necessarily contain the same value it contained in the installer.</p>
  504. <a name="functions"></a><h2>4.7 Functions</h2>
  505. <p>Functions are similar to Sections in that they contain zero or more instructions. User functions are not called by the installer directly, instead they are called from Sections using the <a href="Chapter4.html#call">Call</a> instruction. Callback functions will be called by the installer when a certain event occurs.</p>
  506. <p>Functions must be declared outside of Sections or other Functions.</p>
  507. <a name="ffunctioncommands"></a><h3>4.7.1 Function Commands</h3>
  508. <a name="ffunction"></a><h4>4.7.1.1 Function</h4>
  509. <pre>[function_name]
  510. </pre>
  511. <p>Begins and opens a new function. <a href="Chapter4.html#ffunction">Function</a> names beginning with &quot;.&quot; (e.g. &quot;.Whatever&quot;) are generally reserved for callback functions. <a href="Chapter4.html#ffunction">Function</a> names beginning with &quot;un.&quot; are functions that will be generated in the Uninstaller. Hence, normal install Sections and functions cannot call uninstall functions, and the Uninstall Section and uninstall functions cannot call normal functions.</p>
  512. <pre>Function func
  513. # some commands
  514. FunctionEnd
  515. Section
  516. Call func
  517. SectionEnd
  518. </pre>
  519. <a name="ffunctionend"></a><h4>4.7.1.2 FunctionEnd</h4>
  520. <p>This command closes the current open function.</p>
  521. <a name="callbacks"></a><h3>4.7.2 Callback Functions</h3>
  522. <p>You can create callback functions (which have special names), that will be called by the installer at certain points in the install. Below is a list of available callbacks:</p>
  523. <a name="instcallbacks"></a><h4>4.7.2.1 Install Callbacks</h4>
  524. <a name="onguiinit"></a><h5>4.7.2.1.1 .onGUIInit</h5>
  525. <p>This callback will be called just before the first page is loaded and the installer dialog is shown, allowing you to tweak the user interface.</p>
  526. <p>Example:</p>
  527. <pre> !include &quot;WinMessages.nsh&quot;
  528. Function .onGUIInit
  529. # 1028 is the id of the branding text control
  530. GetDlgItem $R0 $HWNDPARENT 1028
  531. CreateFont $R1 &quot;Tahoma&quot; 10 700
  532. SendMessage $R0 ${WM_SETFONT} $R1 0
  533. # set background color to white and text color to red
  534. SetCtlColors $R0 FFFFFF FF0000
  535. FunctionEnd
  536. </pre>
  537. <a name="oninit"></a><h5>4.7.2.1.2 .onInit</h5>
  538. <p>This callback will be called when the installer is nearly finished initializing. If the '.onInit' function calls <a href="Chapter4.html#abort">Abort</a>, the installer will quit instantly.</p>
  539. <p>Here are two examples of how this might be used:</p>
  540. <pre> Function .onInit
  541. MessageBox MB_YESNO &quot;This will install. Continue?&quot; IDYES NoAbort
  542. Abort ; causes installer to quit.
  543. NoAbort:
  544. FunctionEnd
  545. </pre>
  546. <p>or:</p>
  547. <pre> Function .onInit
  548. ReadINIStr $INSTDIR $WINDIR\wincmd.ini Configuration InstallDir
  549. StrCmp $INSTDIR &quot;&quot; 0 NoAbort
  550. MessageBox MB_OK &quot;Windows Commander not found. Unable to get install path.&quot;
  551. Abort ; causes installer to quit.
  552. NoAbort:
  553. FunctionEnd
  554. </pre>
  555. <a name="oninstfailed"></a><h5>4.7.2.1.3 .onInstFailed</h5>
  556. <p>This callback is called when the user hits the 'cancel' button after the install has failed (if it could not extract a file, or the install script used the <a href="Chapter4.html#abort">Abort</a> command).</p>
  557. <p>Example:</p>
  558. <pre> Function .onInstFailed
  559. MessageBox MB_OK &quot;Better luck next time.&quot;
  560. FunctionEnd
  561. </pre>
  562. <a name="oninstsuccess"></a><h5>4.7.2.1.4 .onInstSuccess</h5>
  563. <p>This callback is called when the install was successful, right before the install window closes (which may be after the user clicks 'Close' if <a href="Chapter4.html#aautoclosewindow">AutoCloseWindow</a> or <a href="Chapter4.html#setautoclose">SetAutoClose</a> is set to false).</p>
  564. <p>Example:</p>
  565. <pre> Function .onInstSuccess
  566. MessageBox MB_YESNO &quot;Congrats, it worked. View readme?&quot; IDNO NoReadme
  567. Exec notepad.exe ; view readme or whatever, if you want.
  568. NoReadme:
  569. FunctionEnd
  570. </pre>
  571. <a name="onguiend"></a><h5>4.7.2.1.5 .onGUIEnd</h5>
  572. <p>This callback is called right after the installer window closes. Use it to free any user interface related plug-ins if needed.</p>
  573. <a name="onmouseoversection"></a><h5>4.7.2.1.6 .onMouseOverSection</h5>
  574. <p>This callback is called whenever the mouse position over the sections tree has changed. This allows you to set a description for each section for example. The section id on which the mouse is over currently is stored, temporarily, in $0.</p>
  575. <p>Example:</p>
  576. <pre> Function .onMouseOverSection
  577. FindWindow $R0 &quot;#32770&quot; &quot;&quot; $HWNDPARENT
  578. GetDlgItem $R0 $R0 1043 ; description item (must be added to the UI)
  579. StrCmp $0 0 &quot;&quot; +2
  580. SendMessage $R0 ${WM_SETTEXT} 0 &quot;STR:first section description&quot;
  581. StrCmp $0 1 &quot;&quot; +2
  582. SendMessage $R0 ${WM_SETTEXT} 0 &quot;STR:second section description&quot;
  583. FunctionEnd
  584. </pre>
  585. <a name="onrebootfailed"></a><h5>4.7.2.1.7 .onRebootFailed</h5>
  586. <p>This callback is called if <a href="Chapter4.html#reboot">Reboot</a> fails. <a href="Chapter4.html#writeuninstaller">WriteUninstaller</a>, <a href="Chapter4.html#plugindlls">plug-ins</a>, <a href="Chapter4.html#file">File</a> and <a href="Chapter4.html#writeregbin">WriteRegBin</a> should not be used in this callback.</p>
  587. <p>Example:</p>
  588. <pre> Function .onRebootFailed
  589. MessageBox MB_OK|MB_ICONSTOP &quot;Reboot failed. Please reboot manually.&quot; /SD IDOK
  590. FunctionEnd
  591. </pre>
  592. <a name="onselchange"></a><h5>4.7.2.1.8 .onSelChange</h5>
  593. <p>Called when the selection changes on the <a href="Chapter4.html#pages">component page</a>. Useful for using with <a href="Chapter4.html#sectionsetflags">SectionSetFlags</a> and <a href="Chapter4.html#sectiongetflags">SectionGetFlags</a>.</p>
  594. <p>Selection changes include both section selection and installation type changes. The section id of the changed section is stored in $0. $0 is -1 if the installation type changed. You only get notifications for changes initiated by the user and only one notification per action even if the action also affected child sections and/or parent groups.</p>
  595. <a name="onuserabort"></a><h5>4.7.2.1.9 .onUserAbort</h5>
  596. <p>This callback is called when the user hits the 'cancel' button, and the install hasn't already failed. If this function calls <a href="Chapter4.html#abort">Abort</a>, the install will not be aborted.</p>
  597. <p>Example:</p>
  598. <pre> Function .onUserAbort
  599. MessageBox MB_YESNO &quot;Abort install?&quot; IDYES NoCancelAbort
  600. Abort ; causes installer to not quit.
  601. NoCancelAbort:
  602. FunctionEnd
  603. </pre>
  604. <a name="onverifyinstdir"></a><h5>4.7.2.1.10 .onVerifyInstDir</h5>
  605. <p>This callback enables control over whether or not an installation path is valid for your installer. This code will be called every time the user changes the install directory, so it shouldn't do anything crazy with <a href="Chapter4.html#messagebox">MessageBox</a> or the like. If this function calls <a href="Chapter4.html#abort">Abort</a>, the installation path in $INSTDIR is deemed invalid.</p>
  606. <p>Example:</p>
  607. <pre> Function .onVerifyInstDir
  608. IfFileExists $INSTDIR\Winamp.exe PathGood
  609. Abort ; if $INSTDIR is not a winamp directory, don't let us install there
  610. PathGood:
  611. FunctionEnd
  612. </pre>
  613. <a name="uninstcallbacks"></a><h4>4.7.2.2 Uninstall Callbacks</h4>
  614. <a name="unonguiinit"></a><h5>4.7.2.2.1 un.onGUIInit</h5>
  615. <p>This callback will be called just before the first page is loaded and the installer dialog is shown, allowing you to tweak the user interface.</p>
  616. <p>Have a look at <a href="Chapter4.html#onguiinit">.onGUIInit</a> for an example.</p>
  617. <a name="unonInit"></a><h5>4.7.2.2.2 un.onInit</h5>
  618. <p>This callback will be called when the uninstaller is nearly finished initializing. If the ' <a href="Chapter4.html#unonInit">un.onInit</a>' function calls <a href="Chapter4.html#abort">Abort</a>, the uninstaller will quit instantly. Note that this function can verify and/or modify $INSTDIR if necessary.</p>
  619. <p>Here are two examples of how this might be used:</p>
  620. <pre> Function un.onInit
  621. MessageBox MB_YESNO &quot;This will uninstall. Continue?&quot; IDYES NoAbort
  622. Abort ; causes uninstaller to quit.
  623. NoAbort:
  624. FunctionEnd
  625. </pre>
  626. <p>or:</p>
  627. <pre> Function un.onInit
  628. IfFileExists $INSTDIR\myfile.exe found
  629. Messagebox MB_OK &quot;Uninstall path incorrect&quot;
  630. Abort
  631. found:
  632. FunctionEnd
  633. </pre>
  634. <a name="unonuninstfailed"></a><h5>4.7.2.2.3 un.onUninstFailed</h5>
  635. <p>This callback is called when the user hits the 'cancel' button after the uninstall has failed (if it used the <a href="Chapter4.html#abort">Abort command</a> or otherwise failed).</p>
  636. <p>Example:</p>
  637. <pre> Function un.onUninstFailed
  638. MessageBox MB_OK &quot;Better luck next time.&quot;
  639. FunctionEnd
  640. </pre>
  641. <a name="unonuninstsuccess"></a><h5>4.7.2.2.4 un.onUninstSuccess</h5>
  642. <p>This callback is called when the uninstall was successful, right before the install window closes (which may be after the user clicks 'Close' if <a href="Chapter4.html#setautoclose">SetAutoClose</a> is set to false)..</p>
  643. <p>Example:</p>
  644. <pre> Function un.onUninstSuccess
  645. MessageBox MB_OK &quot;Congrats, it's gone.&quot;
  646. FunctionEnd
  647. </pre>
  648. <a name="unonguiend"></a><h5>4.7.2.2.5 un.onGUIEnd</h5>
  649. <p>This callback is called right after the uninstaller window closes. Use it to free any user interface related plug-ins if needed.</p>
  650. <a name="unonrebootfailed"></a><h5>4.7.2.2.6 un.onRebootFailed</h5>
  651. <p>This callback is called if <a href="Chapter4.html#reboot">Reboot</a> fails. <a href="Chapter4.html#writeuninstaller">WriteUninstaller</a>, <a href="Chapter4.html#plugindlls">plug-ins</a>, <a href="Chapter4.html#file">File</a> and <a href="Chapter4.html#writeregbin">WriteRegBin</a> should not be used in this callback.</p>
  652. <p>Example:</p>
  653. <pre> Function un.onRebootFailed
  654. MessageBox MB_OK|MB_ICONSTOP &quot;Reboot failed. Please reboot manually.&quot; /SD IDOK
  655. FunctionEnd
  656. </pre>
  657. <a name="unonselchange"></a><h5>4.7.2.2.7 un.onSelChange</h5>
  658. <p>Called when the selection changes on the <a href="Chapter4.html#pages">component page</a>. Useful for using with <a href="Chapter4.html#sectionsetflags">SectionSetFlags</a> and <a href="Chapter4.html#sectiongetflags">SectionGetFlags</a>.</p>
  659. <p>Selection changes include both section selection and installation type changes. The section id of the changed section is stored in $0. $0 is -1 if the installation type changed. You only get notifications for changes initiated by the user and only one notification per action even if the action also affected child sections and/or parent groups.</p>
  660. <a name="unonuserabort"></a><h5>4.7.2.2.8 un.onUserAbort</h5>
  661. <p>This callback is called when the user hits the 'cancel' button and the uninstall hasn't already failed. If this function calls <a href="Chapter4.html#abort">Abort</a>, the install will not be aborted.</p>
  662. <p>Example:</p>
  663. <pre> Function un.onUserAbort
  664. MessageBox MB_YESNO &quot;Abort uninstall?&quot; IDYES NoCancelAbort
  665. Abort ; causes uninstaller to not quit.
  666. NoCancelAbort:
  667. FunctionEnd
  668. </pre>
  669. <a name="instattribs"></a><h2>4.8 Installer Attributes</h2>
  670. <a name="attribgen"></a><h3>4.8.1 General Attributes</h3>
  671. <p>The commands below all adjust attributes of the installer. These attributes control how the installer looks and functions, including which pages are present in the installer, which text is displayed in each part of each page, the name of the installer, the icon the installer uses, the default installation directory and more. Note that these attributes can be set anywhere in the file except in a <a href="Chapter4.html#ssection">Section</a> or <a href="Chapter4.html#ffunction">Function</a>.</p>
  672. <p><b><u>Defaults are bold and underlined</u></b></p>
  673. <a name="aaddbrandingimage"></a><h4>4.8.1.1 AddBrandingImage</h4>
  674. <pre>(left|right|top|bottom) (width|height) [padding]
  675. </pre>
  676. <p>Adds a branding image on the top, bottom, left, or right of the installer. Its size will be set according to the width/height specified, the installer width/height and the installers font. The final size will not always be what you requested; have a look at the output of the command for the actual size. Because this depends on the installers font, you should use <a href="Chapter4.html#asetfont">SetFont</a> before <a href="Chapter4.html#aaddbrandingimage">AddBrandingImage</a>. The default padding value is 2.</p>
  677. <p><a href="Chapter4.html#aaddbrandingimage">AddBrandingImage</a> only adds a placeholder for an image. To set the image itself at runtime, use <a href="Chapter4.html#setbrandingimage">SetBrandingImage</a>.</p>
  678. <pre>AddBrandingImage left 100
  679. AddBrandingImage right 50
  680. AddBrandingImage top 20
  681. AddBrandingImage bottom 35
  682. AddBrandingImage left 100 5
  683. </pre>
  684. <a name="aallowrootdirinstall"></a><h4>4.8.1.2 AllowRootDirInstall</h4>
  685. <pre>true|<b>false</b>
  686. </pre>
  687. <p>Controls whether or not installs are allowed in the root directory of a drive, or directly into a network share. Set to 'true' to change the safe behavior, which prevents users from selecting C:\ or \\Server\Share as an install (and later on, uninstall) directory. For additional directory selection page customizability, see <a href="Chapter4.html#onverifyinstdir">.onVerifyInstDir</a>.</p>
  688. <a name="aautoclosewindow"></a><h4>4.8.1.3 AutoCloseWindow</h4>
  689. <pre>true|<b>false</b>
  690. </pre>
  691. <p>Sets whether or not the install window automatically closes when completed. This is overrideable from a section using <a href="Chapter4.html#setautoclose">SetAutoClose</a>.</p>
  692. <a name="abgfont"></a><h4>4.8.1.4 BGFont</h4>
  693. <pre>[font_face [height [weight] [/ITALIC] [/UNDERLINE] [/STRIKE]]]
  694. </pre>
  695. <p>Specifies the font used to show the text on the background gradient. To set the color use <a href="Chapter4.html#abggradient">BGGradient</a>. The default font will be used if no parameters are specified. The default font is bold and italic Times New Roman.</p>
  696. <a name="abggradient"></a><h4>4.8.1.5 BGGradient</h4>
  697. <pre>[<b>off</b>|(topc botc [textcolor|notext])]
  698. </pre>
  699. <p>Specifies whether or not to use a gradient background window. If 'off', the installer will not show a background window, if no parameters are specified, the default black to blue gradient is used, and otherwise the top_color or bottom_color are used to make a gradient. Top_color and bottom_color are specified using the form RRGGBB (in hexadecimal, as in HTML, only minus the leading '#', since # can be used for comments). 'textcolor' can be specified as well, or 'notext' can be specified to turn the big background text off.</p>
  700. <a name="abrandingtext"></a><h4>4.8.1.6 BrandingText</h4>
  701. <pre>/TRIM(LEFT|RIGHT|CENTER) text
  702. </pre>
  703. <p>Sets the text that is shown at the bottom of the install window (by default it is 'Nullsoft Install System vX.XX'). Setting this to an empty string (&quot;&quot;) uses the default; to set the string to blank, use &quot; &quot; (a space). If it doesn't matter to you, leave it the default so that everybody can know why the installer didn't suck :). Use /TRIMLEFT, /TRIMRIGHT or /TRIMCENTER to trim down the size of the control to the size of the string.</p>
  704. <p>Accepts variables. If variables are used, they must be initialized on <a href="Chapter4.html#oninit">.onInit</a>.</p>
  705. <a name="acaption"></a><h4>4.8.1.7 Caption</h4>
  706. <pre>caption
  707. </pre>
  708. <p>When used outside a <a href="Chapter4.html#pageex">PageEx</a> block: Sets the text for the titlebar of the installer. By default it is '$(^Name) Setup', where Name is specified by the <a href="Chapter4.html#aname">Name</a> instruction. You can however override it with 'MyApp Installer' or whatever. If you specify an empty string (&quot;&quot;), the default will be used (you can specify &quot; &quot; to simulate a empty string).</p>
  709. <p>When used inside a <a href="Chapter4.html#pageex">PageEx</a> block: Sets the subcaption of the current page.</p>
  710. <p>Accepts variables. If variables are used, they must be initialized on <a href="Chapter4.html#oninit">.onInit</a>.</p>
  711. <a name="achangeui"></a><h4>4.8.1.8 ChangeUI</h4>
  712. <pre>dialog ui_file.exe
  713. </pre>
  714. <p>Replaces dialog (<em>IDD_LICENSE</em>, <em>IDD_DIR</em>, <em>IDD_SELCOM</em>, <em>IDD_INST</em>, <em>IDD_INSTFILES</em>, <em>IDD_UNINST</em> or <em>IDD_VERIFY</em>) with a dialog from ui_file.exe with the same resource ID. You can also specify 'all' as the dialog if you wish to replace all 7 of the dialogs at once from the same UI file. For some example UIs look at Contrib\UIs under your NSIS directory.</p>
  715. <ul>
  716. <li><em>IDD_LICENSE</em> must contain <em>IDC_EDIT1</em> (RICHEDIT control).</li><li><em>IDD_DIR</em> must contain <em>IDC_DIR</em> (edit box), <em>IDC_BROWSE</em> (button) and <em>IDC_CHECK1</em> (checkbox).</li><li><em>IDD_SELCOM</em> must contain <em>IDC_TREE1</em> (SysTreeView32 control), and <em>IDC_COMBO1</em> (combo box).</li><li><em>IDD_INST</em> must contain <em>IDC_BACK</em> (button), <em>IDC_CHILDRECT</em> (static control the size of all other dialogs), <em>IDC_VERSTR</em> (static), <em>IDOK</em> (button), and <em>IDCANCEL</em> (button). If an image control (static with <em>SS_BITMAP</em> style) will be found in this dialog it will be used as the default for <a href="Chapter4.html#setbrandingimage">SetBrandingImage</a>.</li><li><em>IDD_INSTFILES</em> must contain <em>IDC_LIST1</em> (SysListView32 control), <em>IDC_PROGRESS</em> (msctls_progress32 control), and <em>IDC_SHOWDETAILS</em> (button).</li><li><em>IDD_UNINST</em> must contain <em>IDC_EDIT1</em> (edit box).</li><li><em>IDD_VERIFY</em> must contain <em>IDC_STR</em> (static).</li></ul>
  717. <pre>ChangeUI all &quot;${NSISDIR}\Contrib\UIs\sdbarker_tiny.exe&quot;
  718. </pre>
  719. <a name="acheckbitmap"></a><h4>4.8.1.9 CheckBitmap</h4>
  720. <pre>bitmap.bmp
  721. </pre>
  722. <p>Specifies the bitmap with the checkbox images used in the component-selection page treeview.</p>
  723. <p>This bitmap should have a size of 96x16 pixels, no more than 8bpp (256 colors) and contain six 16x16 images for the different states (in order: selection mask, not checked, checked, greyed out, unchecked &amp; read-only, checked &amp; read-only). Use magenta as mask color (this area will be transparent).</p>
  724. <a name="acompletedtext"></a><h4>4.8.1.10 CompletedText</h4>
  725. <pre>text
  726. </pre>
  727. <p>Replaces the default text (&quot;Completed&quot;) that is printed at the end of the install if parameter is specified. Otherwise, the default is used.</p>
  728. <p>Accepts variables. If variables are used, they must be initialized before the message is printed.</p>
  729. <a name="acomponenttext"></a><h4>4.8.1.11 ComponentText</h4>
  730. <pre>[text [subtext] [subtext2]]
  731. </pre>
  732. <p>Used to change the default text on the component page.</p>
  733. <p>text: Text above the controls, to the right of the installation icon.</p>
  734. <p>subtext: Text next to the installation type selection.</p>
  735. <p>subtext2: Text to the left of the components list and below the installation type.</p>
  736. <p>The default string will be used if a string is empty (&quot;&quot;).</p>
  737. <p>Accepts variables. If variables are used, they must be initialized before the components page is created.</p>
  738. <a name="acrccheck"></a><h4>4.8.1.12 CRCCheck</h4>
  739. <pre><b>on</b>|off|force
  740. </pre>
  741. <p>Specifies whether or not the installer will perform a CRC on itself before allowing an install. Note that if the user uses /NCRC on the command line when executing the installer, and you didn't specify 'force', the CRC will not occur, and the user will be allowed to install a (potentially) corrupted installer.</p>
  742. <a name="adetailsbuttontext"></a><h4>4.8.1.13 DetailsButtonText</h4>
  743. <pre>show_details_text
  744. </pre>
  745. <p>Replaces the default details button text of &quot;Show details&quot;, if parameter is specified (otherwise the default is used).</p>
  746. <p>Accepts variables. If variables are used, they must be initialized before the install log (instfiles) page is created.</p>
  747. <a name="adirtext"></a><h4>4.8.1.14 DirText</h4>
  748. <pre>[text] [subtext] [browse_button_text] [browse_dlg_text]
  749. </pre>
  750. <p>Used to change the default text on the directory page.</p>
  751. <p>text: Text above the controls, to the right of the installation icon.</p>
  752. <p>subtext: Text on the directory selection frame.</p>
  753. <p>browse_button_text: Text on the Browse button.</p>
  754. <p>browse_dlg_text: Text on the &quot;Browse For Folder&quot; dialog, appears after clicking on &quot;Browse&quot; button.</p>
  755. <p>The default string will be used if a string is empty (&quot;&quot;).</p>
  756. <p>Accepts variables. If variables are used, they must be initialized before the directory page is created.</p>
  757. <a name="adirvar"></a><h4>4.8.1.15 DirVar</h4>
  758. <pre>user_var(dir input/output)
  759. </pre>
  760. <p>Specifies which variable is to be used to contain the directory selected. This variable should be initialized with a default value. This allows you to easily create two different directory pages that will not require you to move values in and out of $INSTDIR. The default variable is $INSTDIR. This can only be used in <a href="Chapter4.html#pageex">PageEx</a> for directory and uninstConfirm pages.</p>
  761. <pre>Var ANOTHER_DIR
  762. PageEx directory
  763. DirVar $ANOTHER_DIR
  764. PageExEnd
  765. Section
  766. SetOutPath $INSTDIR
  767. File &quot;a file.dat&quot;
  768. SetOutPath $ANOTHER_DIR
  769. File &quot;another file.dat&quot;
  770. SectionEnd
  771. </pre>
  772. <a name="adirverify"></a><h4>4.8.1.16 DirVerify</h4>
  773. <pre><b>auto</b>|leave
  774. </pre>
  775. <p>If `<a href="Chapter4.html#adirverify">DirVerify</a> leave' is used, the Next button will not be disabled if the installation directory is not valid or there is not enough space. A flag that you can read in the leave function using <a href="Chapter4.html#getinstdirerror">GetInstDirError</a> will be set instead.</p>
  776. <pre>PageEx directory
  777. DirVerify leave
  778. PageCallbacks &quot;&quot; &quot;&quot; dirLeave
  779. PageExEnd
  780. </pre>
  781. <a name="a"></a><h4>4.8.1.17 FileErrorText</h4>
  782. <pre>file_error_text [noignore_file_error_text]
  783. </pre>
  784. <p>Replaces the default text that comes up when a file cannot be written to. This string can contain a reference to $0, which is the filename ($0 is temporarily changed to this value). Example: &quot;Can not write to file $\r$\n$0$\r$\ngood luck.&quot;.</p>
  785. <p>Accepts variables. If variables are used, they must be initialized before <a href="Chapter4.html#file">File</a> is used.</p>
  786. <a name="aicon"></a><h4>4.8.1.18 Icon</h4>
  787. <pre>[path\]icon.ico
  788. </pre>
  789. <p>Sets the icon of the installer. Every image in the icon file will be included in the installer. Use <a href="Chapter4.html#auninstallicon">UninstallIcon</a> to set the uninstaller icon.</p>
  790. <a name="ainstallbuttontext"></a><h4>4.8.1.19 InstallButtonText</h4>
  791. <pre>install_button_text
  792. </pre>
  793. <p>If parameter is specified, overrides the default install button text (of &quot;Install&quot;) with the specified text.</p>
  794. <p>Accepts variables. If variables are used, they must be initialized before the install button shows.</p>
  795. <a name="ainstallcolors"></a><h4>4.8.1.20 InstallColors</h4>
  796. <pre>/windows | (foreground_color background_color)
  797. </pre>
  798. <p>Sets the colors to use for the install info screen (the default is 00FF00 000000. Use the form RRGGBB (in hexadecimal, as in HTML, only minus the leading '#', since # can be used for comments). Note that if &quot;/windows&quot; is specified as the only parameter, the default windows colors will be used.</p>
  799. <a name="ainstalldir"></a><h4>4.8.1.21 InstallDir</h4>
  800. <pre>definstdir
  801. </pre>
  802. <p>Sets the default installation directory. See the <a href="Chapter4.html#variables">variables section</a> for variables that can be used to make this string (especially $PROGRAMFILES). Note that the part of this string following the last \ will be used if the user selects 'browse', and may be appended back on to the string at install time (to disable this, end the directory with a \ (which will require the entire parameter to be enclosed with quotes). If this doesn't make any sense, play around with the browse button a bit.</p>
  803. <a name="ainstalldirregkey"></a><h4>4.8.1.22 InstallDirRegKey</h4>
  804. <pre>root_key subkey key_name
  805. </pre>
  806. <p>This attribute tells the installer to check a string in the registry and use it as the install dir if that string is valid. If this attribute is present, it will override the <a href="Chapter4.html#ainstalldir">InstallDir</a> attribute if the registry key is valid, otherwise it will fall back to the <a href="Chapter4.html#ainstalldir">InstallDir</a> value. When querying the registry, this command will automatically remove any quotes. If the string ends in &quot;.exe&quot;, it will automatically remove the filename component of the string (i.e. if the string is &quot;C:\Program Files\Foo\app.exe&quot;, it will know to use &quot;C:\Program Files\Foo&quot;). For more advanced install directory configuration, set $INSTDIR in .onInit.</p>
  807. <p>Language strings and variables cannot be used with <a href="Chapter4.html#ainstalldirregkey">InstallDirRegKey</a>.</p>
  808. <pre>InstallDirRegKey HKLM Software\NSIS &quot;&quot;
  809. InstallDirRegKey HKLM Software\ACME\Thingy InstallLocation
  810. </pre>
  811. <a name="ainstprogressflags"></a><h4>4.8.1.23 InstProgressFlags</h4>
  812. <pre>[flag [...]]
  813. </pre>
  814. <p>Valid values for flag are &quot;smooth&quot; (smooth the progress bar) or &quot;colored&quot; (color the progress bar with the colors set by <a href="Chapter4.html#ainstallcolors">InstallColors</a>. Examples: &quot;InstProgressFlags&quot; (default old-school windows look), &quot;InstProgressFlags smooth&quot; (new smooth look), &quot;InstProgressFlags smooth colored&quot; (colored smooth look whee). Note: neither &quot;smooth&quot; or &quot;colored&quot; work with <a href="Chapter4.html#axpstyle">XPStyle</a> on when the installer runs on Windows XP with a modern theme.</p>
  815. <a name="ainsttype"></a><h4>4.8.1.24 InstType</h4>
  816. <pre>install_type_name | /NOCUSTOM | /CUSTOMSTRING=str | /COMPONENTSONLYONCUSTOM
  817. </pre>
  818. <p>Adds an install type to the install type list, or disables the custom install type. There can be as many as 32 types, each one specifying the name of the install type. If the name is prefixed with 'un.' it is an uninstaller install type. The name can contain variables which will be processed at runtime before the components page shows. Another way of changing the <a href="Chapter4.html#ainsttype">InstType</a> name during runtime is the <a href="Chapter4.html#sinsttypesettext">InstTypeSetText</a> command. The difference is that with <a href="Chapter4.html#sinsttypesettext">InstTypeSetText</a> you are saving your precious user variables. The first type is the default (generally 'Typical'). If the /NOCUSTOM switch is specified, then the &quot;custom&quot; install type is disabled, and the user has to choose one of the pre-defined install types. Alternatively, if the /CUSTOMSTRING switch is specified, the parameter will override the &quot;Custom&quot; install type text. Alternatively, if the /COMPONENTSONLYONCUSTOM flag is specified, the component list will only be shown if the &quot;Custom&quot; install type is selected.</p>
  819. <p>Accepts variables for type names. If variables are used, they must be initialized before the components page is created.</p>
  820. <a name="alicensebkcolor"></a><h4>4.8.1.25 LicenseBkColor</h4>
  821. <pre>color | <b>/gray</b> | /windows
  822. </pre>
  823. <p>Sets the background color of the license data. Color is specified using the form RRGGBB (in hexadecimal, as in HTML, only minus the leading '#', since # can be used for comments). Default is '/gray'. You can also use the Windows OS defined color by using '/windows'.</p>
  824. <a name="alicensedata"></a><h4>4.8.1.26 LicenseData</h4>
  825. <pre>licdata.(txt|rtf)
  826. </pre>
  827. <p>Specifies a text file or a RTF file to use for the license that the user can read. Omit this to not have a license displayed. Note that the file must be in DOS text format (\r\n). To define a multilingual license data use <a href="Chapter4.html#licenselangstring">LicenseLangString</a>.</p>
  828. <p>If you are using a RTF file it is recommended that you edit it with WordPad and not MS Word. Using WordPad will result in a much smaller file.</p>
  829. <p>Use <a href="Chapter4.html#licenselangstring">LicenseLangString</a> to show a different license for every language.</p>
  830. <a name="alicenseforceselection"></a><h4>4.8.1.27 LicenseForceSelection</h4>
  831. <pre>(checkbox [accept_text] | radiobuttons [accept_text] [decline_text] | <b>off</b>)
  832. </pre>
  833. <p>Specifies if the displayed license must be explicitly accepted or not. This can be done either by a checkbox or by radiobuttons. By default the &quot;next button&quot; is disabled and will only be enabled if the checkbox is enabled or the correct radio button is selected. If off is specified the &quot;next button&quot; is enabled by default.</p>
  834. <pre>LicenseForceSelection checkbox
  835. LicenseForceSelection checkbox &quot;i accept&quot;
  836. LicenseForceSelection radiobuttons
  837. LicenseForceSelection radiobuttons &quot;i accept&quot;
  838. LicenseForceSelection radiobuttons &quot;i accept&quot; &quot;i decline&quot;
  839. LicenseForceSelection radiobuttons &quot;&quot; &quot;i decline&quot;
  840. LicenseForceSelection off
  841. </pre>
  842. <a name="alicensetext"></a><h4>4.8.1.28 LicenseText</h4>
  843. <pre>[text [button_text]]
  844. </pre>
  845. <p>Used to change the default text on the license page.</p>
  846. <p>text: Text above the controls, to the right of the installation icon.</p>
  847. <p>button_text: Text on the &quot;I Agree&quot; button.</p>
  848. <p>The default string will be used if a string is empty (&quot;&quot;).</p>
  849. <p>Accepts variables. If variables are used, they must be initialized before the license page is created.</p>
  850. <a name="amanifestdpiaware"></a><h4>4.8.1.29 ManifestDPIAware</h4>
  851. <pre><b>notset</b>|true|false
  852. </pre>
  853. <p>Declare that the installer is DPI-aware. A DPI-aware application is not scaled by the DWM (DPI virtualization) so the text is never blurry. NSIS does not scale the bitmap used by the tree control on the component page and some plugins might have compatibility issues so make sure that you test your installer at different DPI settings if you select <em>true</em>.</p>
  854. <p>See <a href="http://msdn.microsoft.com/en-us/library/dd464660">MSDN</a> for more information about DPI-aware applications.</p>
  855. <a name="amanifestsupportedos"></a><h4>4.8.1.30 ManifestSupportedOS</h4>
  856. <pre>none|all|WinVista|<b>Win7|Win8|Win8.1|Win10</b>|{GUID} [...]
  857. </pre>
  858. <p>Declare that the installer is compatible with the specified Windows version(s). This adds a SupportedOS entry in the compatibility section of the application manifest. The default is Win7+8+8.1+10. <em>none</em> is the default if <a href="Chapter4.html#arequestexecutionlevel">RequestExecutionLevel</a> is set to <em>none</em> for compatibility reasons.</p>
  859. <p>Windows 8.1 and later will fake its version number if you don't declare support for that particular version. You can read more about the other changes in behavior on <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh848036">MSDN</a>.</p>
  860. <a name="amiscbuttontext"></a><h4>4.8.1.31 MiscButtonText</h4>
  861. <pre>[back_button_text [next_button_text] [cancel_button_text] [close_button_text]]
  862. </pre>
  863. <p>Replaces the default text strings for the four buttons (&lt; Back, Next &gt;, Cancel and Close). If parameters are omitted, the defaults are used.</p>
  864. <p>Accepts variables. If variables are used, they must be initialized in <a href="Chapter4.html#oninit">.onInit</a>.</p>
  865. <a name="aname"></a><h4>4.8.1.32 Name</h4>
  866. <pre>name [name_doubled_ampersands]
  867. </pre>
  868. <p>Sets the name of the installer. The name is usually simply the product name such as 'MyApp' or 'CrapSoft MyApp'. If you have one or more ampersands (&amp;) in the name, set the second parameter to the same name, only with doubled ampersands. For example, if your product's name is &quot;Foo &amp; Bar&quot;, use:</p>
  869. <pre> Name &quot;Foo &amp; Bar&quot; &quot;Foo &amp;&amp; Bar&quot;
  870. </pre>
  871. <p>If you have ampersands in the name and use a <a href="Chapter4.html#langstring">LangString</a> for the name, you will have to create another one with doubled ampersands to use as the second parameter.</p>
  872. <p>Accepts variables. If variables are used, they must be initialized in <a href="Chapter4.html#oninit">.onInit</a>.</p>
  873. <a name="aoutfile"></a><h4>4.8.1.33 OutFile</h4>
  874. <pre>[path\]install.exe
  875. </pre>
  876. <p>Specifies the output file that the MakeNSIS should write the installer to. This is just the file that MakeNSIS writes, it doesn't affect the contents of the installer.</p>
  877. <a name="arequestexecutionlevel"></a><h4>4.8.1.34 RequestExecutionLevel</h4>
  878. <pre>none|user|highest|<b>admin</b>
  879. </pre>
  880. <p>Specifies the requested execution level for Windows Vista and higher. The value is embedded in the installer and uninstaller's XML manifest and tells Windows which privilege level the installer requires. <em>user</em> requests the user's normal level with no administrative privileges. <em>highest</em> will request the highest execution level available for the current user and will cause Windows to prompt the user to verify privilege escalation if they are a member of the administrators group. The prompt might request for the user's password. <em>admin</em>, which is also the default, requests administrator level and will cause Windows to prompt the user as well. Specifying <em>none</em> will keep the manifest empty and let Windows decide which execution level is required. Windows automatically identifies NSIS installers and decides administrator privileges are required. Because of this, <em>none</em> and <em>admin</em> have virtually the same effect.</p>
  881. <p>It's recommended that every application is marked with a required execution level. Unmarked installers are subject to compatibility mode. Workarounds of this mode include automatically moving any shortcuts created in the user's start menu to all users' start menu. Installers that don't install anything into system folders nor write to the local machine registry (HKLM) should specify <em>user</em> execution level.</p>
  882. <p>More information about this topic can be found on <a href="http://msdn.microsoft.com/en-us/library/bb756929">MSDN</a>.</p>
  883. <a name="asetfont"></a><h4>4.8.1.35 SetFont</h4>
  884. <pre>[/LANG=lang_id] font_face_name font_size
  885. </pre>
  886. <p>Sets the installer font. Please remember that the font you choose must be present on the user's machine as well. Don't use rare fonts that only you have.</p>
  887. <p>Use the /LANG switch if you wish to set a different font for each language. For example:</p>
  888. <pre> SetFont /LANG=${LANG_ENGLISH} &quot;English Font&quot; 9
  889. SetFont /LANG=${LANG_FRENCH} &quot;French Font&quot; 10
  890. </pre>
  891. <p>There are two <a href="Chapter4.html#langstring">LangString</a>s named ^Font and ^FontSize which contain the font and font size for every language.</p>
  892. <a name="ashowinstdetails"></a><h4>4.8.1.36 ShowInstDetails</h4>
  893. <pre><b>hide</b>|show|nevershow
  894. </pre>
  895. <p>Sets whether or not the details of the install are shown. Can be 'hide' to hide the details by default, allowing the user to view them, or 'show' to show them by default, or 'nevershow', to prevent the user from ever seeing them. Note that sections can override this using <a href="Chapter4.html#setdetailsview">SetDetailsView</a>.</p>
  896. <a name="ashowuninstdetails"></a><h4>4.8.1.37 ShowUninstDetails</h4>
  897. <pre><b>hide</b>|show|nevershow
  898. </pre>
  899. <p>Sets whether or not the details of the uninstall are shown. Can be 'hide' to hide the details by default, allowing the user to view them, or 'show' to show them by default, or 'nevershow', to prevent the user from ever seeing them. Note that sections can override this using <a href="Chapter4.html#setdetailsview">SetDetailsView</a>.</p>
  900. <a name="asilentinstall"></a><h4>4.8.1.38 SilentInstall</h4>
  901. <pre><b>normal</b>|silent|silentlog
  902. </pre>
  903. <p>Specifies whether or not the installer should be silent. If it is 'silent' or 'silentlog', all sections that have the SF_SELECTED flag are installed quietly (you can set this flag using <a href="Chapter4.html#sectionsetflags">SectionSetFlags</a>), with no screen output from the installer itself (the script can still display whatever it wants, use <a href="Chapter4.html#messagebox">MessageBox</a>'s /SD to specify a default for silent installers). Note that if this is set to 'normal' and the user runs the installer with /S (case sensitive) on the command line, it will behave as if <a href="Chapter4.html#asilentinstall">SilentInstall</a> 'silent' was used. Note: see also <a href="Chapter4.html#logset">LogSet</a>.</p>
  904. <p>See <a href="Chapter4.html#silent">section 4.12</a> for more information.</p>
  905. <a name="asilentuninstall"></a><h4>4.8.1.39 SilentUnInstall</h4>
  906. <pre><b>normal</b>|silent
  907. </pre>
  908. <p>Specifies whether or not the uninstaller should be silent. If it is 'silent' the uninstall sections will run quietly, with no screen output from the uninstaller itself (the script can still display whatever it wants, use <a href="Chapter4.html#messagebox">MessageBox</a>'s /SD to specify a default for silent uninstallers). Note that if this is set to 'normal' and the user runs the uninstaller with /S on the command line, it will behave as if <a href="Chapter4.html#asilentuninstall">SilentUnInstall</a> 'silent' was used.</p>
  909. <p>See <a href="Chapter4.html#silent">section 4.12</a> for more information.</p>
  910. <a name="aspacetexts"></a><h4>4.8.1.40 SpaceTexts</h4>
  911. <pre>[req_text [avail_text]]
  912. </pre>
  913. <p>If parameters are specified, overrides the space required and space available text (&quot;Space required: &quot; and &quot;Space available: &quot; by default). If 'none' is specified as the required text no space texts will be shown.</p>
  914. <p>Accepts variables. If variables are used, they must be initialized before the components page is created.</p>
  915. <a name="asubcaption"></a><h4>4.8.1.41 SubCaption</h4>
  916. <pre>[page_number subcaption]
  917. </pre>
  918. <p>Overrides the subcaptions for each of the installer pages (0=&quot;: License Agreement&quot;,1=&quot;: Installation Options&quot;,2=&quot;: Installation Directory&quot;, 3=&quot;: Installing Files&quot;, 4=&quot;: Completed&quot;). If you specify an empty string (&quot;&quot;), the default will be used (you can however specify &quot; &quot; to achieve a blank string).</p>
  919. <p>You can also set a subcaption (or override the default) using <a href="Chapter4.html#acaption">Caption</a> inside a <a href="Chapter4.html#pageex">PageEx</a> block.</p>
  920. <p>Accepts variables. If variables are used, they must be initialized before the relevant page is created.</p>
  921. <a name="auninstallbuttontext"></a><h4>4.8.1.42 UninstallButtonText</h4>
  922. <pre>text
  923. </pre>
  924. <p>Changes the text of the button that by default says &quot;Uninstall&quot; in the uninstaller. If no parameter is specified, the default text is used.</p>
  925. <p>Accepts variables. If variables are used, they must be initialized before the uninstall button shows.</p>
  926. <a name="auninstallcaption"></a><h4>4.8.1.43 UninstallCaption</h4>
  927. <pre>caption
  928. </pre>
  929. <p>Sets what the titlebars of the uninstaller will display. By default it is '$(^Name) Uninstall', where Name is specified with the Name command. You can, however, override it with 'MyApp uninstaller' or whatever. If you specify an empty string (&quot;&quot;), the default will be used (you can specify &quot; &quot; to simulate a empty string).</p>
  930. <p>Accepts variables. If variables are used, they must be initialized in <a href="Chapter4.html#unonInit">un.onInit</a>.</p>
  931. <a name="auninstallicon"></a><h4>4.8.1.44 UninstallIcon</h4>
  932. <pre>[path\]icon.ico
  933. </pre>
  934. <p>Sets the icon of the uninstaller.</p>
  935. <a name="auninstallsubcaption"></a><h4>4.8.1.45 UninstallSubCaption</h4>
  936. <pre>page_number subcaption
  937. </pre>
  938. <p>Sets the default subcaptions for the uninstaller pages (0=&quot;: Confirmation&quot;,1=&quot;: Uninstalling Files&quot;,2=&quot;: Completed&quot;). If you specify an empty string (&quot;&quot;), the default will be used (you can specify &quot; &quot; to simulate a empty string).</p>
  939. <p>You can also set a subcaption (or override the default) using <a href="Chapter4.html#acaption">Caption</a> inside a <a href="Chapter4.html#pageex">PageEx</a> block.</p>
  940. <p>Accepts variables. If variables are used, they must be initialized before the relevant page is created.</p>
  941. <a name="auninstalltext"></a><h4>4.8.1.46 UninstallText</h4>
  942. <pre>text [subtext]
  943. </pre>
  944. <p>Specifies the texts on the uninstaller confirm page.</p>
  945. <p>text: Text above the controls</p>
  946. <p>subtext: Text next to the uninstall location</p>
  947. <p>Accepts variables. If variables are used, they must be initialized before the uninstaller confirm page is created.</p>
  948. <a name="awindowicon"></a><h4>4.8.1.47 WindowIcon</h4>
  949. <pre><b>on</b>|off
  950. </pre>
  951. <p>Sets whether or not the installer's icon is displayed on certain pages.</p>
  952. <a name="axpstyle"></a><h4>4.8.1.48 XPStyle</h4>
  953. <pre>on|<b>off</b>
  954. </pre>
  955. <p>Sets whether or not a XP visual style manifest will be added to the installer. This manifest makes the installers controls use the new visual styles when running on Windows XP and later. This affects the uninstaller too.</p>
  956. <a name="flags"></a><h3>4.8.2 Compiler Flags</h3>
  957. <p>The following commands affect how the compiler generates code and compresses data. Unless otherwise noted, these commands are valid anywhere in the script and affect every line below where each one is placed (until overridden by another command). They cannot be jumped over using <a href="Chapter4.html#flowcontrol">flow control instructions</a>.</p>
  958. <p>For example, in the following script, blah.dat will never be overwritten.</p>
  959. <pre>${If} $0 == 0
  960. SetOverwrite on
  961. ${Else}
  962. SetOverwrite off
  963. ${EndIf}
  964. File blah.dat # overwrite is always off here!
  965. </pre>
  966. <p>Instead, the following should be used.</p>
  967. <pre>${If} $0 == 0
  968. SetOverwrite on
  969. File blah.dat
  970. ${Else}
  971. SetOverwrite off
  972. File blah.dat
  973. ${EndIf}
  974. </pre>
  975. <a name="asetallowskipfiles"></a><h4>4.8.2.1 AllowSkipFiles</h4>
  976. <pre><b>on</b>|off
  977. </pre>
  978. <p>This command specifies whether the user should be able to skip a file or not. A user has an option to skip a file if <a href="Chapter4.html#asetoverwrite">SetOverwrite</a> is set to on (default) and the installer fails to open a file for writing when trying to extract a file. If <em>off</em> is used the ignore button which allows the user to skip the file will not be shown and the user will only have an option to abort the installation (Cancel button) or retry opening the file for writing (Retry button). If <em>on</em> is used the user will have an option to skip the file (error flag will be set - see <a href="Chapter4.html#asetoverwrite">SetOverwrite</a>).</p>
  979. <a name="afilebufsize"></a><h4>4.8.2.2 FileBufSize</h4>
  980. <pre>buffer_size_in_mb
  981. </pre>
  982. <p>This command sets the size of the compiler's internal file buffers. This command allows you to control the compiler's memory usage by limiting how much of a given file it will load into memory at once. Since the compiler needs both input and output, twice the memory size specified could be used at any given time for file buffers. This command does not limit the compression buffers which could take another couple of MB, neither does it limit the compiler's other internal buffers, but those shouldn't normally top 1MB anyway. Specifying a very small number could decrease performance. Specifying a very large number could exhaust system resources and force the compiler to cancel the compilation process. The default value is 32MB.</p>
  983. <a name="asetcompress"></a><h4>4.8.2.3 SetCompress</h4>
  984. <pre><b>auto</b>|force|off
  985. </pre>
  986. <p>This command sets the compress flag which is used by the installer to determine whether or not data should be compressed. Typically the <a href="Chapter4.html#asetcompress">SetCompress</a> flag will affect the commands after it, and the last <a href="Chapter4.html#asetcompress">SetCompress</a> command in the file also determines whether or not the install info section and uninstall data of the installer is compressed. If compressflag is 'auto', then files are compressed if the compressed size is smaller than the uncompressed size. If compressflag is set to 'force', then the compressed version is always used. If compressflag is 'off' then compression is not used (which can be faster).</p>
  987. <p>Note that this option has no effect when solid compression is used.</p>
  988. <a name="asetcompressor"></a><h4>4.8.2.4 SetCompressor</h4>
  989. <pre>[/SOLID] [/FINAL] <b>zlib</b>|bzip2|lzma
  990. </pre>
  991. <p>This command sets the compression algorithm used to compress files/data in the installer. It can only be used outside of sections and functions and before any data is compressed. Different compression methods can not be used for different files in the same installer. It is recommended to use it at the very top of the script to avoid compilation errors.</p>
  992. <p>Three compression methods are supported: ZLIB, BZIP2 and LZMA.</p>
  993. <p>ZLIB (the default) uses the deflate algorithm, it is a quick and simple method. With the default compression level it uses about 300 KB of memory.</p>
  994. <p>BZIP2 usually gives better compression ratios than ZLIB, but it is a bit slower and uses more memory. With the default compression level it uses about 4 MB of memory.</p>
  995. <p>LZMA is a new compression method that gives very good compression ratios. The decompression speed is high (10-20 MB/s on a 2 GHz CPU), the compression speed is lower. The memory size that will be used for decompression is the dictionary size plus a few KBs, the default is 8 MB.</p>
  996. <p>If <em>/FINAL</em> is used, subsequent calls to <a href="Chapter4.html#asetcompressor">SetCompressor</a> will be ignored.</p>
  997. <p>If <em>/SOLID</em> is used, all of the installer data is compressed in one block. This results in greater compression ratios.</p>
  998. <a name="asetcompressordictsize"></a><h4>4.8.2.5 SetCompressorDictSize</h4>
  999. <pre>dict_size_mb
  1000. </pre>
  1001. <p>Sets the dictionary size in megabytes (MB) used by the LZMA compressor (default is 8 MB).</p>
  1002. <a name="asetdatablockoptimize"></a><h4>4.8.2.6 SetDatablockOptimize</h4>
  1003. <pre><b>on</b>|off
  1004. </pre>
  1005. <p>This command tells the compiler whether or not to do datablock optimizations. Datablock optimizations causes the compiler to check to see if any data being added to the data block is already in the data block, and if so, it is simply referenced as opposed to added (can save a little bit of size). It is highly recommended to leave this option on.</p>
  1006. <a name="asetdatesave"></a><h4>4.8.2.7 SetDateSave</h4>
  1007. <pre><b>on</b>|off
  1008. </pre>
  1009. <p>This command sets the file date/time saving flag which is used by the <a href="Chapter4.html#file">File</a> command to determine whether or not to save the last write date and time of the file, so that it can be restored on installation. Valid flags are 'on' and 'off'. 'on' is the default.</p>
  1010. <a name="asetoverwrite"></a><h4>4.8.2.8 SetOverwrite</h4>
  1011. <pre><b>on</b>|off|try|ifnewer|ifdiff|lastused
  1012. </pre>
  1013. <p>This command sets the overwrite flag which is used by the <a href="Chapter4.html#file">File</a> command to determine whether or not the file should overwrite any existing files that are present. If overwriteflag is 'on', files are overwritten (this is the default). If overwriteflag is 'off', files that are already present are not overwritten. If overwriteflag is 'try', files are overwritten if possible (meaning that if the file is not able to be written to, it is skipped without any user interaction). If overwriteflag is 'ifnewer', then files are only overwritten if the existing file is older than the new file. If overwriteflag is 'ifdiff', then files are only overwritten if the existing file is older or newer than the new file. Note that when in 'ifnewer' or 'ifdiff' mode, the destination file's date is set, regardless of what <a href="Chapter4.html#asetdatesave">SetDateSave</a> is set to.</p>
  1014. <pre>SetOverwrite off
  1015. File program.cfg # config file we don't want to overwrite
  1016. SetOverwrite on
  1017. </pre>
  1018. <a name="aunicodetarget"></a><h4>4.8.2.9 Unicode</h4>
  1019. <pre>true|<b>false</b>
  1020. </pre>
  1021. <p>Generate a <a href="Chapter1.html#intro-unicode">Unicode installer</a>. It can only be used outside of sections and functions and before any data is compressed.</p>
  1022. <a name="versioninfo"></a><h3>4.8.3 Version Information</h3>
  1023. <a name="viaddversionkey"></a><h4>4.8.3.1 VIAddVersionKey</h4>
  1024. <pre> [/LANG=lang_id] keyname value
  1025. </pre>
  1026. <p>Adds a string entry to the version information stored in the installer and uninstaller. These can be viewed in the File Properties Version or Details tab. keyname can either be a special name known by Windows or a user defined name. /LANG=0 can be used to indicate a language neutral language id. The following names are known by Windows:</p>
  1027. <ul>
  1028. <li>ProductName</li><li>Comments</li><li>CompanyName</li><li>LegalCopyright</li><li>FileDescription</li><li>FileVersion</li><li>ProductVersion</li><li>InternalName</li><li>LegalTrademarks</li><li>OriginalFilename</li><li>PrivateBuild</li><li>SpecialBuild</li></ul>
  1029. <p>The displayed name of these special entries are translated on the target system, whereas user defined keynames remain untranslated.</p>
  1030. <pre>VIAddVersionKey /LANG=${LANG_ENGLISH} &quot;ProductName&quot; &quot;Test Application&quot;
  1031. VIAddVersionKey /LANG=${LANG_ENGLISH} &quot;Comments&quot; &quot;A test comment&quot;
  1032. VIAddVersionKey /LANG=${LANG_ENGLISH} &quot;CompanyName&quot; &quot;Fake company&quot;
  1033. VIAddVersionKey /LANG=${LANG_ENGLISH} &quot;LegalTrademarks&quot; &quot;Test Application is a trademark of Fake company&quot;
  1034. VIAddVersionKey /LANG=${LANG_ENGLISH} &quot;LegalCopyright&quot; &quot;&#0169; Fake company&quot;
  1035. VIAddVersionKey /LANG=${LANG_ENGLISH} &quot;FileDescription&quot; &quot;Test Application&quot;
  1036. VIAddVersionKey /LANG=${LANG_ENGLISH} &quot;FileVersion&quot; &quot;1.2.3&quot;
  1037. </pre>
  1038. <a name="viproductversion"></a><h4>4.8.3.2 VIProductVersion</h4>
  1039. <pre>[version_string_X.X.X.X]
  1040. </pre>
  1041. <p>Sets the Product Version in the VS_FIXEDFILEINFO version information block.</p>
  1042. <pre>VIProductVersion 1.2.3.4
  1043. </pre>
  1044. <a name="vifileversion"></a><h4>4.8.3.3 VIFileVersion</h4>
  1045. <pre>[version_string_X.X.X.X]
  1046. </pre>
  1047. <p>Sets the File Version in the VS_FIXEDFILEINFO version information block (You should also set the FileVersion string with VIAddVersionKey so the information is displayed at the top of the Version Tab in the Properties of the file). If you don't provide a File Version the Product Version is used in the VS_FIXEDFILEINFO block.</p>
  1048. <pre>VIFileVersion 1.2.3.4
  1049. </pre>
  1050. <a name="instr"></a><h2>4.9 Instructions</h2>
  1051. <a name="basicinstructions"></a><h3>4.9.1 Basic Instructions</h3>
  1052. <p>The instructions that NSIS uses for scripting are sort of a cross between PHP and assembly. There are no real high level language constructs but the instructions themselves are (for the most part) high level, and you have handy string capability (i.e. you don't have to worry about concatenating strings, etc). You essentially have 25 registers (20 general purpose, 5 special purpose), and a stack.</p>
  1053. <a name="delete"></a><h4>4.9.1.1 Delete</h4>
  1054. <pre>[/REBOOTOK] file
  1055. </pre>
  1056. <p>Delete file (which can be a file or wildcard, but should be specified with a full path) from the target system. If /REBOOTOK is specified and the file cannot be deleted then the file is deleted when the system reboots -- if the file will be deleted on a reboot, the reboot flag will be set. The error flag is set if files are found and cannot be deleted. The error flag is not set when trying to delete a file that does not exist.</p>
  1057. <pre>Delete $INSTDIR\somefile.dat
  1058. </pre>
  1059. <p><div class="wb"> <b>Warning:</b> The /REBOOTOK switch requires administrator rights on Windows NT and later. </div></p>
  1060. <a name="exec"></a><h4>4.9.1.2 Exec</h4>
  1061. <pre>command
  1062. </pre>
  1063. <p>Execute the specified program and continue immediately. Note that the file specified must exist on the target system, not the compiling system. $OUTDIR is used as the working directory. The error flag is set if the process could not be launched. Note, if the command could have spaces, you should put it in quotes to delimit it from parameters. e.g.: Exec '&quot;$INSTDIR\command.exe&quot; parameters'. If you don't put it in quotes it will <em>not</em> work on Windows 9x with or without parameters.</p>
  1064. <pre>Exec '&quot;$INSTDIR\someprogram.exe&quot;'
  1065. Exec '&quot;$INSTDIR\someprogram.exe&quot; some parameters'
  1066. </pre>
  1067. <a name="execshell"></a><h4>4.9.1.3 ExecShell</h4>
  1068. <pre>action command [parameters] [SW_SHOWDEFAULT | SW_SHOWNORMAL | SW_SHOWMAXIMIZED | SW_SHOWMINIMIZED | SW_HIDE]
  1069. </pre>
  1070. <p>Execute the specified program using ShellExecute. Note that action is usually &quot;open&quot;, &quot;print&quot;, etc, but can be an empty string to use the default action. Parameters and the show type are optional. $OUTDIR is used as the working directory. The error flag is set if the process could not be launched.</p>
  1071. <pre>ExecShell &quot;open&quot; &quot;http://nsis.sf.net/&quot;
  1072. ExecShell &quot;open&quot; &quot;$INSTDIR\readme.txt&quot;
  1073. ExecShell &quot;print&quot; &quot;$INSTDIR\readme.txt&quot;
  1074. </pre>
  1075. <a name="execwait"></a><h4>4.9.1.4 ExecWait</h4>
  1076. <pre>command [user_var(exit code)]
  1077. </pre>
  1078. <p>Execute the specified program and wait for the executed process to quit. See <a href="Chapter4.html#exec">Exec</a> for more information. If no output variable is specified <a href="Chapter4.html#execwait">ExecWait</a> sets the error flag if the program executed returns a nonzero error code, or if there is an error. If an output variable is specified, <a href="Chapter4.html#execwait">ExecWait</a> sets the variable with the exit code (and only sets the error flag if an error occurs; if an error occurs the contents of the user variable are undefined). Note, if the command could have spaces, you should put it in quotes to delimit it from parameters. e.g.: ExecWait '&quot;$INSTDIR\command.exe&quot; parameters'. If you don't put it in quotes it will <em>not</em> work on Windows 9x with or without parameters.</p>
  1079. <pre>ExecWait '&quot;$INSTDIR\someprogram.exe&quot;'
  1080. ExecWait '&quot;$INSTDIR\someprogram.exe&quot;' $0
  1081. DetailPrint &quot;some program returned $0&quot;
  1082. </pre>
  1083. <a name="file"></a><h4>4.9.1.5 File</h4>
  1084. <pre>[/nonfatal] [/a] ([/r] [/x file|wildcard [...]] (file|wildcard) [...] | /oname=file.dat infile.dat)
  1085. </pre>
  1086. <p>Adds file(s) to be extracted to the current output path ($OUTDIR).</p>
  1087. <ul>
  1088. <li>Note that the output file name is $OUTDIR\filename_portion_of_file.</li><li>Use /oname=X switch to change the output name. X may contain variables and can be a fully qualified path or a relative path in which case it will be appended to $OUTDIR set by <a href="Chapter4.html#setoutpath">SetOutPath</a>. When using this switch, only one file can be specified. If the output name contains spaces, quote the entire parameter, including /oname, as shown in the examples below.</li><li>Wildcards are supported.</li><li>If the /r switch is used, matching files and directories are recursively searched for in subdirectories. If just one path segment is specified (e.g. <code>File /r something</code>), the current directory will be recursively searched. If more than one segment is specified (e.g. <code>File /r something\*.*</code>), the last path segment will be used as the matching condition and anything before it specifies which directory to search recursively. If a directory name matches, all of its contents is added recursively. Directory structure is preserved.</li><li>Use the /x switch to exclude files and directories.</li><li>If the /a switch is used, the attributes of the file(s) added will be preserved.</li><li>The <a href="Chapter4.html#file">File</a> command sets the error flag if overwrite mode is set to 'try' and the file could not be overwritten, or if the overwrite mode is set to 'on' and the file could not be overwritten and the user selects ignore.</li><li>If the /nonfatal switch is used and no files are found, a warning will be issued instead of an error.</li></ul>
  1089. <pre>File something.exe
  1090. File /a something.exe
  1091. File *.exe
  1092. File /r *.dat
  1093. File /r data
  1094. File /oname=temp.dat somefile.ext
  1095. File /oname=$TEMP\temp.dat somefile.ext
  1096. File &quot;/oname=$TEMP\name with spaces.dat&quot; somefile.ext
  1097. File /nonfatal &quot;a file that might not exist&quot;
  1098. File /r /x CVS myproject\*.*
  1099. File /r /x *.res /x *.obj /x *.pch source\*.*
  1100. </pre>
  1101. <p><b>Note:</b> when using the <em>/r</em> switch, both matching directories and files will be searched. This is always done with or without the use of wildcards, even if the given path perfectly matches one directory. That means, the following directory structure:</p>
  1102. <pre>&lt;DIR&gt; something
  1103. file.dat
  1104. another.dat
  1105. &lt;DIR&gt; dir
  1106. something
  1107. &lt;DIR&gt; dir2
  1108. file2.dat
  1109. &lt;DIR&gt; another
  1110. &lt;DIR&gt; something
  1111. readme.txt
  1112. </pre>
  1113. <p>with the following <em>File</em> usage:</p>
  1114. <pre>File /r something
  1115. </pre>
  1116. <p>will match the directory named <em>something</em> in the root directory, the file named <em>something</em> in the directory named <em>dir</em> and the directory named <em>something</em> in the directory named <em>another</em>. To match only the directory named <em>something</em> in the root directory, use the following:</p>
  1117. <pre>File /r something\*.*
  1118. </pre>
  1119. <p>When adding <em>\*.*</em>, it will be used as the matching condition and <em>something</em> will be used as the directory to search. When only <em>something</em> is specified, the current directory will be recursively searched for every file and directory named <em>something</em> and <em>another\something</em> will be matched.</p>
  1120. <a name="rename"></a><h4>4.9.1.6 Rename</h4>
  1121. <pre>[/REBOOTOK] source_file dest_file
  1122. </pre>
  1123. <p>Rename source_file to dest_file. You can use it to move a file from anywhere on the system to anywhere else and you can move a directory to somewhere else on the same drive. The destination file must not exist or the move will fail (unless you are using /REBOOTOK). If /REBOOTOK is specified, and the file cannot be moved (if, for example, the destination exists), then the file is moved when the system reboots. If the file will be moved on a reboot, the reboot flag will be set. The error flag is set if the file cannot be renamed (and /REBOOTOK is not used) or if the source file does not exist.</p>
  1124. <p>If no absolute path is specified the current folder will be used. The current folder is the folder set using the last <a href="Chapter4.html#setoutpath">SetOutPath</a> instruction. If you have not used <a href="Chapter4.html#setoutpath">SetOutPath</a> the current folder is <a href="Chapter4.html#varother">$EXEDIR</a>.</p>
  1125. <pre>Rename $INSTDIR\file.ext $INSTDIR\file.dat
  1126. </pre>
  1127. <p><div class="wb"> <b>Warning:</b> The /REBOOTOK switch requires administrator rights on Windows NT and later. </div></p>
  1128. <a name="reservefile"></a><h4>4.9.1.7 ReserveFile</h4>
  1129. <pre>[/nonfatal] [/r] [/x file|wildcard [...]] file [file...] | [/nonfatal] /plugin file.dll
  1130. </pre>
  1131. <p>Reserves a file in the data block for later use. Files are added to the compressed data block in the order they appear in the script. Functions, however, are not necessarily called in the order they appear in the script. Therefore, if you add a file in a function called early but put the function at the end of the script, all of the files added earlier will have to be decompressed to get to the required file. This process can take a long time if there a lot of files. <a href="Chapter4.html#oninit">.onInit</a> is one such function. It is called at the very beginning, before anything else appears. If you put it at the very end of the script, extract some files in it and have lots of files added before it, the installer might take a very long time to load. This is where this command comes useful, allowing you to speed up the loading process by including the file at the top of the data block instead of letting NSIS seek all the way down to the bottom of the <em>compressed</em> data block.</p>
  1132. <p>Use /plugin to reserve a plugin in ${NSISDIR}\Plugins\*.</p>
  1133. <p>See <a href="Chapter4.html#file">File</a> for more information about the parameters.</p>
  1134. <a name="rmdir"></a><h4>4.9.1.8 RMDir</h4>
  1135. <pre>[/r] [/REBOOTOK] directory_name
  1136. </pre>
  1137. <p>Remove the specified directory (fully qualified path with no wildcards). Without /r, the directory will only be removed if it is completely empty. If /r is specified the directory will be removed recursively, so all directories and files in the specified directory will be removed. If /REBOOTOK is specified, any file or directory which could not be removed during the process will be removed on reboot -- if any file or directory will be removed on a reboot, the reboot flag will be set. The error flag is set if any file or directory cannot be removed.</p>
  1138. <pre>RMDir $INSTDIR
  1139. RMDir $INSTDIR\data
  1140. RMDir /r /REBOOTOK $INSTDIR
  1141. RMDir /REBOOTOK $INSTDIR\DLLs
  1142. </pre>
  1143. <p>Note that the current working directory can not be deleted. The current working directory is set by <a href="Chapter4.html#setoutpath">SetOutPath</a>. For example, the following example will not delete the directory.</p>
  1144. <pre>SetOutPath $TEMP\dir
  1145. RMDir $TEMP\dir
  1146. </pre>
  1147. <p>The next example will succeed in deleting the directory.</p>
  1148. <pre>SetOutPath $TEMP\dir
  1149. SetOutPath $TEMP
  1150. RMDir $TEMP\dir
  1151. </pre>
  1152. <p><div class="wb"> <b>Warning:</b> Using <em>RMDir /r $INSTDIR</em> in the uninstaller is not safe. Though it is unlikely, the user might select to install to the root of the Program Files folder and this command would wipe out the entire Program Files folder, including all other installed programs! The user can also put other files in the installation folder and wouldn't expect them to get deleted along with the program. Solutions are <a href="http://nsis.sourceforge.net/Uninstall_only_installed_files">available</a> for easily uninstalling only files which were installed by the installer. </div></p>
  1153. <p><div class="wb"> <b>Warning:</b> The /REBOOTOK switch requires administrator rights on Windows NT and later. </div></p>
  1154. <a name="setoutpath"></a><h4>4.9.1.9 SetOutPath</h4>
  1155. <pre>outpath
  1156. </pre>
  1157. <p>Sets the output path ($OUTDIR) and creates it (recursively if necessary), if it does not exist. Must be a full pathname, usually is just $INSTDIR (you can specify $INSTDIR with a single &quot;-&quot; if you are lazy).</p>
  1158. <pre>SetOutPath $INSTDIR
  1159. File program.exe
  1160. </pre>
  1161. <a name="registry"></a><h3>4.9.2 Registry, INI, File Instructions</h3>
  1162. <p>In all of the below registry instructions use an empty string (just two quotes with nothing between them - &quot;&quot;) as the key name to specify the default key which is shown as (Default) in regedit.exe.</p>
  1163. <p>Use <a href="Chapter4.html#setregview">SetRegView</a> on Windows x64 to choose which registry view is used.</p>
  1164. <p>If a full path is not specified for any of the INI handling instructions, the Windows directory will be used.</p>
  1165. <a name="deleteinisec"></a><h4>4.9.2.1 DeleteINISec</h4>
  1166. <pre>ini_filename section_name
  1167. </pre>
  1168. <p>Deletes the entire section [section_name] from ini_filename. If the section could not be removed from the ini file, the error flag is set. It does not set the error flag if the section could not be found.</p>
  1169. <pre>WriteINIStr $TEMP\something.ini section1 something 123
  1170. WriteINIStr $TEMP\something.ini section1 somethingelse 1234
  1171. WriteINIStr $TEMP\something.ini section2 nsis true
  1172. DeleteINISec $TEMP\something.ini section1
  1173. </pre>
  1174. <a name="deleteinistr"></a><h4>4.9.2.2 DeleteINIStr</h4>
  1175. <pre>ini_filename section_name str_name
  1176. </pre>
  1177. <p>Deletes the string str_name from section [section_name] from ini_filename. If the string could not be removed from the ini file, the error flag is set. It does not set the error flag if the string could not be found.</p>
  1178. <pre>WriteINIStr $TEMP\something.ini section1 something 123
  1179. WriteINIStr $TEMP\something.ini section1 somethingelse 1234
  1180. DeleteINIStr $TEMP\something.ini section1 somethingelse
  1181. </pre>
  1182. <a name="deleteregkey"></a><h4>4.9.2.3 DeleteRegKey</h4>
  1183. <pre>[/ifempty] root_key subkey
  1184. </pre>
  1185. <p>Deletes a registry key. If /ifempty is specified, the registry key will only be deleted if it has no subkeys (otherwise, the whole registry tree will be removed). Valid values for root_key are listed under <a href="Chapter4.html#writeregstr">WriteRegStr</a>. The error flag is set if the key could not be removed from the registry (or if it didn't exist to begin with).</p>
  1186. <pre>DeleteRegKey HKLM &quot;Software\My Company\My Software&quot;
  1187. DeleteRegKey /ifempty HKLM &quot;Software\A key that might have subkeys&quot;
  1188. </pre>
  1189. <a name="deleteregvalue"></a><h4>4.9.2.4 DeleteRegValue</h4>
  1190. <pre>root_key subkey key_name
  1191. </pre>
  1192. <p>Deletes a registry value. Valid values for root_key are listed under <a href="Chapter4.html#writeregstr">WriteRegStr</a>. The error flag is set if the value could not be removed from the registry (or if it didn't exist to begin with).</p>
  1193. <pre>DeleteRegValue HKLM &quot;Software\My Company\My Software&quot; &quot;some value&quot;
  1194. </pre>
  1195. <a name="enumregkey"></a><h4>4.9.2.5 EnumRegKey</h4>
  1196. <pre>user_var(output) root_key subkey index
  1197. </pre>
  1198. <p>Set user variable $x with the name of the 'index'th registry key in root_key\Subkey. Valid values for root_key are listed under <a href="Chapter4.html#writeregstr">WriteRegStr</a>. Returns an empty string if there are no more keys, and returns an empty string and sets the error flag if there is an error.</p>
  1199. <pre>StrCpy $0 0
  1200. loop:
  1201. EnumRegKey $1 HKLM Software $0
  1202. StrCmp $1 &quot;&quot; done
  1203. IntOp $0 $0 + 1
  1204. MessageBox MB_YESNO|MB_ICONQUESTION &quot;$1$\n$\nMore?&quot; IDYES loop
  1205. done:
  1206. </pre>
  1207. <a name="enumregvalue"></a><h4>4.9.2.6 EnumRegValue</h4>
  1208. <pre>user_var(output) root_key subkey index
  1209. </pre>
  1210. <p>Set user variable $x with the name of the 'index'th registry value in root_key\Subkey. Valid values for root_key are listed under <a href="Chapter4.html#writeregstr">WriteRegStr</a>. Returns an empty string and sets the error flag if there are no more values or if there is an error.</p>
  1211. <pre>StrCpy $0 0
  1212. loop:
  1213. ClearErrors
  1214. EnumRegValue $1 HKLM Software\Microsoft\Windows\CurrentVersion $0
  1215. IfErrors done
  1216. IntOp $0 $0 + 1
  1217. ReadRegStr $2 HKLM Software\Microsoft\Windows\CurrentVersion $1
  1218. MessageBox MB_YESNO|MB_ICONQUESTION &quot;$1 = $2$\n$\nMore?&quot; IDYES loop
  1219. done:
  1220. </pre>
  1221. <a name="expandenvstrings"></a><h4>4.9.2.7 ExpandEnvStrings</h4>
  1222. <pre>user_var(output) string
  1223. </pre>
  1224. <p>Expands environment variables in <em>string</em> into the user variable <em>$x</em>. If an environment variable doesn't exist, it will not be replaced. For example, if you use &quot;%var%&quot; and var doesn't exists, the result will be &quot;%var%&quot;. If there is an error, the variable is set to empty, and the error flag is set.</p>
  1225. <pre>ExpandEnvStrings $0 &quot;WINDIR=%WINDIR%$\nTEMP=%TEMP%&quot;
  1226. </pre>
  1227. <a name="flushini"></a><h4>4.9.2.8 FlushINI</h4>
  1228. <pre>ini_filename
  1229. </pre>
  1230. <p>Flushes the INI file's buffers. Windows 9x keeps all changes to the INI file in memory. This command causes the changes to be written to the disk immediately. Use it if you edit the INI manually, delete it, move it or copy it right after you change it with <a href="Chapter4.html#writeinistr">WriteINIStr</a>, <a href="Chapter4.html#deleteinisec">DeleteINISec</a> or <a href="Chapter4.html#deleteinistr">DeleteINStr</a>.</p>
  1231. <pre>WriteINIStr $TEMP\something.ini test test test
  1232. FlushINI $TEMP\something.ini
  1233. Delete $TEMP\something.ini
  1234. </pre>
  1235. <a name="readenvstr"></a><h4>4.9.2.9 ReadEnvStr</h4>
  1236. <pre>user_var(output) name
  1237. </pre>
  1238. <p>Reads from the environment string &quot;name&quot; and sets the value into the user variable $x. If there is an error reading the string, the user variable is set to empty, and the error flag is set.</p>
  1239. <pre>ReadEnvStr $0 WINDIR
  1240. ReadEnvStr $1 TEMP
  1241. </pre>
  1242. <a name="readinistr"></a><h4>4.9.2.10 ReadINIStr</h4>
  1243. <pre>user_var(output) ini_filename section_name entry_name
  1244. </pre>
  1245. <p>Reads from entry_name in [section_name] of ini_filename and stores the value into user variable $x. The error flag will be set and $x will be assigned to an empty string if the entry is not found.</p>
  1246. <pre>ReadINIStr $0 $INSTDIR\winamp.ini winamp outname
  1247. </pre>
  1248. <a name="readregdword"></a><h4>4.9.2.11 ReadRegDWORD</h4>
  1249. <pre>user_var(output) root_key sub_key name
  1250. </pre>
  1251. <p>Reads a 32-bit DWORD from the registry into the user variable $x. Valid values for root_key are listed under <a href="Chapter4.html#writeregstr">WriteRegStr</a>. The error flag will be set and $x will be set to an empty string (&quot;&quot; which is interpreted as 0 in math operations) if the DWORD is not present. If the value is present, but is not a DWORD, it will be read as a string and the error flag will be set.</p>
  1252. <pre>ReadRegDWORD $0 HKLM Software\NSIS VersionBuild
  1253. </pre>
  1254. <a name="readregstr"></a><h4>4.9.2.12 ReadRegStr</h4>
  1255. <pre>user_var(output) root_key sub_key name
  1256. </pre>
  1257. <p>Reads from the registry into the user variable $x. Valid values for root_key are listed under <a href="Chapter4.html#writeregstr">WriteRegStr</a>. The error flag will be set and $x will be set to an empty string (&quot;&quot;) if the string is not present. If the value is present, but is of type REG_DWORD, it will be read and converted to a string and the error flag will be set.</p>
  1258. <pre>ReadRegStr $0 HKLM Software\NSIS &quot;&quot;
  1259. DetailPrint &quot;NSIS is installed at: $0&quot;
  1260. </pre>
  1261. <a name="writeinistr"></a><h4>4.9.2.13 WriteINIStr</h4>
  1262. <pre>ini_filename section_name entry_name value
  1263. </pre>
  1264. <p>Writes entry_name=value into [section_name] of ini_filename. The error flag is set if the string could not be written to the ini file.</p>
  1265. <pre>WriteINIStr $TEMP\something.ini section1 something 123
  1266. WriteINIStr $TEMP\something.ini section1 somethingelse 1234
  1267. WriteINIStr $TEMP\something.ini section2 nsis true
  1268. </pre>
  1269. <a name="writeregbin"></a><h4>4.9.2.14 WriteRegBin</h4>
  1270. <pre>root_key subkey key_name valuedata
  1271. </pre>
  1272. <p>This command writes a block of binary data to the registry. Valid values for root_key are listed under <a href="Chapter4.html#writeregstr">WriteRegStr</a>. Valuedata is in hexadecimal (e.g. DEADBEEF01223211151). The error flag is set if the binary data could not be written to the registry. If the registry key doesn't exist it will be created.</p>
  1273. <pre>WriteRegBin HKLM &quot;Software\My Company\My Software&quot; &quot;Binary Value&quot; DEADBEEF01223211151
  1274. </pre>
  1275. <a name="writeregdword"></a><h4>4.9.2.15 WriteRegDWORD</h4>
  1276. <pre>root_key subkey key_name value
  1277. </pre>
  1278. <p>This command writes a DWORD (32-bit integer) to the registry (a user variable can be specified). Valid values for root_key are listed under <a href="Chapter4.html#writeregstr">WriteRegStr</a>. The error flag is set if the dword could not be written to the registry. If the registry key doesn't exist it will be created.</p>
  1279. <pre>WriteRegDWORD HKLM &quot;Software\My Company\My Software&quot; &quot;DWORD Value&quot; 0xDEADBEEF
  1280. </pre>
  1281. <a name="writeregstr"></a><h4>4.9.2.16 WriteRegStr</h4>
  1282. <pre>root_key subkey key_name value
  1283. </pre>
  1284. <p>Write a string to the registry. See <a href="Chapter4.html#writeregexpandstr">WriteRegExpandStr</a> for more details.</p>
  1285. <pre>WriteRegStr HKLM &quot;Software\My Company\My Software&quot; &quot;String Value&quot; &quot;dead beef&quot;
  1286. </pre>
  1287. <a name="writeregexpandstr"></a><h4>4.9.2.17 WriteRegExpandStr</h4>
  1288. <pre>root_key subkey key_name value
  1289. </pre>
  1290. <p>Write a string to the registry. <em>root_key</em> must be one of:</p>
  1291. <ul>
  1292. <li><em>HKCR</em> or <em>HKEY_CLASSES_ROOT</em></li><li><em>HKLM</em> or <em>HKEY_LOCAL_MACHINE</em></li><li><em>HKCU</em> or <em>HKEY_CURRENT_USER</em></li><li><em>HKU</em> or <em>HKEY_USERS</em></li><li><em>HKCC</em> or <em>HKEY_CURRENT_CONFIG</em></li><li><em>HKDD</em> or <em>HKEY_DYN_DATA</em></li><li><em>HKPD</em> or <em>HKEY_PERFORMANCE_DATA</em></li><li><em>SHCTX</em> or <em>SHELL_CONTEXT</em></li></ul>
  1293. <p>If <em>root_key</em> is <em>SHCTX</em> or <em>SHELL_CONTEXT</em>, it will be replaced with <em>HKLM</em> if <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> is set to <em>all</em> and with <em>HKCU</em> if <a href="Chapter4.html#setshellvarcontext">SetShellVarContext</a> is set to <em>current</em>.</p>
  1294. <p>The error flag is set if the string could not be written to the registry. The type of the string will be REG_SZ for <a href="Chapter4.html#writeregstr">WriteRegStr</a>, or REG_EXPAND_STR for <a href="Chapter4.html#writeregexpandstr">WriteRegExpandStr</a>. If the registry key doesn't exist it will be created.</p>
  1295. <pre>WriteRegExpandStr HKLM &quot;Software\My Company\My Software&quot; &quot;Expand String Value&quot; &quot;%WINDIR%\notepad.exe&quot;
  1296. </pre>
  1297. <a name="writeregmultistr"></a><h4>4.9.2.18 WriteRegMultiStr</h4>
  1298. <pre>/REGEDIT5 root_key subkey key_name value
  1299. </pre>
  1300. <p>Writes a multi-string value. The /REGEDIT5 switch must be used and specifies that the data is in the hex format used by .reg files on Windows 2000 and later.</p>
  1301. <pre>WriteRegMultiStr /REGEDIT5 HKCU &quot;Software\NSIS\Test&quot; &quot;Multi Value&quot; 66,00,6f,00,6f,00,00,00,62,00,61,00,72,00,00,00,00,00
  1302. </pre>
  1303. <a name="setregview"></a><h4>4.9.2.19 SetRegView</h4>
  1304. <pre><b>32</b>|64|lastused
  1305. </pre>
  1306. <p>Sets the registry view affected by <a href="Chapter4.html#registry">registry commands</a>. On 64-bit versions of Windows there are two views; one for 32-bit applications and one for 64-bit applications. By default, 32-bit applications running on 64-bit systems (WOW64) only have access to the 32-bit view. Using <code>SetRegView 64</code> allows the installer to access keys in the 64-bit view of the registry.</p>
  1307. <p>Affects <a href="Chapter4.html#deleteregkey">DeleteRegKey</a>, <a href="Chapter4.html#deleteregvalue">DeleteRegValue</a>, <a href="Chapter4.html#enumregkey">EnumRegKey</a>, <a href="Chapter4.html#enumregvalue">EnumRegValue</a>, <a href="Chapter4.html#readregdword">ReadRegDWORD</a>, <a href="Chapter4.html#readregstr">ReadRegStr</a>, <a href="Chapter4.html#writeregbin">WriteRegBin</a>, <a href="Chapter4.html#writeregdword">WriteRegDWORD</a>, <a href="Chapter4.html#writeregstr">WriteRegStr</a> and <a href="Chapter4.html#writeregexpandstr">WriteRegExpandStr</a>.</p>
  1308. <p>Does not affect <a href="Chapter4.html#ainstalldirregkey">InstallDirRegKey</a>. Instead, the registry must be read using <a href="Chapter4.html#readregstr">ReadRegStr</a> in <a href="Chapter4.html#oninit">.onInit</a>.</p>
  1309. <pre>SetRegView 32
  1310. ReadRegStr $0 HKLM Software\Microsoft\Windows\CurrentVersion ProgramFilesDir
  1311. DetailPrint $0 # prints C:\Program Files (x86)
  1312. SetRegView 64
  1313. ReadRegStr $0 HKLM Software\Microsoft\Windows\CurrentVersion ProgramFilesDir
  1314. DetailPrint $0 # prints C:\Program Files
  1315. </pre>
  1316. <pre>Function .onInit
  1317. SetRegView 64
  1318. ReadRegStr $INSTDIR HKLM Software\NSIS &quot;&quot;
  1319. SetRegView 32
  1320. FunctionEnd
  1321. </pre>
  1322. <a name="generalpurpose"></a><h3>4.9.3 General Purpose Instructions</h3>
  1323. <a name="callinstdll"></a><h4>4.9.3.1 CallInstDLL</h4>
  1324. <pre>dllfile function_name
  1325. </pre>
  1326. <p>Calls a function named <em>function_name</em> inside a NSIS extension DLL, a plug-in. See the <a href="../Examples/Plugin/">example plugin</a> for how to make one. Extension DLLs can access the stack and variables. Note: To automatically extract and call plug-in DLLs, use a plug-in command instead of <a href="Chapter4.html#callinstdll">CallInstDLL</a>.</p>
  1327. <pre>Push &quot;a parameter&quot;
  1328. Push &quot;another parameter&quot;
  1329. CallInstDLL $INSTDIR\somedll.dll somefunction
  1330. </pre>
  1331. <p>For easier plug-in handling, use the new <a href="Chapter4.html#plugindlls">plug-in call syntax</a>.</p>
  1332. <a name="copyfiles"></a><h4>4.9.3.2 CopyFiles</h4>
  1333. <pre>[/SILENT] [/FILESONLY] filespec_on_destsys destination_path [size_of_files_in_kb]
  1334. </pre>
  1335. <p>Copies files from the source to the destination on the installing system. Useful with $EXEDIR if you want to copy from installation media, or to copy from one place to another on the system. You might see a Windows status window of the copy operation if the operation takes a lot of time (to disable this, use /SILENT). The last parameter can be used to specify the size of the files that will be copied (in kilobytes), so that the installer can approximate the disk space requirements. On error, or if the user cancels the copy (only possible when /SILENT was omitted), the error flag is set. If /FILESONLY is specified, only files are copied.</p>
  1336. <p>Fully-qualified path names should always be used with this instruction. Using relative paths will have unpredictable results.</p>
  1337. <pre>CreateDirectory $INSTDIR\backup
  1338. CopyFiles $INSTDIR\*.dat $INSTDIR\backup
  1339. </pre>
  1340. <a name="createdirectory"></a><h4>4.9.3.3 CreateDirectory</h4>
  1341. <pre>path_to_create
  1342. </pre>
  1343. <p>Creates (recursively if necessary) the specified directory. The error flag is set if the directory couldn't be created.</p>
  1344. <p>You should always specify an absolute path.</p>
  1345. <pre>CreateDirectory $INSTDIR\some\directory
  1346. </pre>
  1347. <a name="createshortcut"></a><h4>4.9.3.4 CreateShortcut</h4>
  1348. <pre>[/NoWorkingDir] link.lnk target.file [parameters [icon.file [icon_index_number [start_options [keyboard_shortcut [description]]]]]]
  1349. </pre>
  1350. <p>Creates a shortcut 'link.lnk' that links to 'target.file', with optional parameters 'parameters'. The icon used for the shortcut is 'icon.file,icon_index_number'; for default icon settings use empty strings for both icon.file and icon_index_number. start_options should be one of: <em>SW_SHOWNORMAL</em>, <em>SW_SHOWMAXIMIZED</em>, <em>SW_SHOWMINIMIZED</em>, or an empty string. keyboard_shortcut should be in the form of 'flag|c' where flag can be a combination (using |) of: <em>ALT</em>, <em>CONTROL</em>, <em>EXT</em>, or <em>SHIFT</em>. c is the character to use (a-z, A-Z, 0-9, F1-F24, etc). Note that no spaces are allowed in this string. A good example is &quot;ALT|CONTROL|F8&quot;. $OUTDIR is used as the working directory. You can change it by using <a href="Chapter4.html#setoutpath">SetOutPath</a> before creating the Shortcut or use /NoWorkingDir if you don't need to set the working directory. description should be the description of the shortcut, or comment as it is called under XP. The error flag is set if the shortcut cannot be created (i.e. either of the paths (link or target) does not exist, or some other error).</p>
  1351. <pre>CreateDirectory &quot;$SMPROGRAMS\My Company&quot;
  1352. CreateShortcut &quot;$SMPROGRAMS\My Company\My Program.lnk&quot; &quot;$INSTDIR\My Program.exe&quot; \
  1353. &quot;some command line parameters&quot; &quot;$INSTDIR\My Program.exe&quot; 2 SW_SHOWNORMAL \
  1354. ALT|CONTROL|SHIFT|F5 &quot;a description&quot;
  1355. </pre>
  1356. <a name="getdllversion"></a><h4>4.9.3.5 GetDLLVersion</h4>
  1357. <pre>filename user_var(high dword output) user_var(low dword output)
  1358. </pre>
  1359. <p>Gets the version information from the DLL (or any other executable containing version information) in &quot;filename&quot;. Sets the user output variables with the high and low dwords of version information on success; on failure the outputs are empty and the error flag is set. The following example reads the DLL version and copies a human readable version of it into $0:</p>
  1360. <pre>GetDllVersion &quot;$INSTDIR\MyDLL.dll&quot; $R0 $R1
  1361. IntOp $R2 $R0 / 0x00010000
  1362. IntOp $R3 $R0 &amp; 0x0000FFFF
  1363. IntOp $R4 $R1 / 0x00010000
  1364. IntOp $R5 $R1 &amp; 0x0000FFFF
  1365. StrCpy $0 &quot;$R2.$R3.$R4.$R5&quot;
  1366. </pre>
  1367. <a name="getdllversionlocal"></a><h4>4.9.3.6 GetDLLVersionLocal</h4>
  1368. <pre>localfilename user_var(high dword output) user_var(low dword output)
  1369. </pre>
  1370. <p>This is similar to <a href="Chapter4.html#getdllversion">GetDLLVersion</a>, only it acts on the system building the installer (it actually compiles into two <a href="Chapter4.html#StrCpy">StrCpy</a> commands). Sets the two output variables with the DLL version information of the DLL on the build system. Use <a href="Chapter5.html#ppgetdllversion">!getdllversion</a> if you need to use the values with <a href="Chapter4.html#viproductversion">VIProductVersion</a>.</p>
  1371. <a name="getfiletime"></a><h4>4.9.3.7 GetFileTime</h4>
  1372. <pre>filename user_var(high dword output) user_var(low dword output)
  1373. </pre>
  1374. <p>Gets the last write time of &quot;filename&quot;. Sets the user output variables with the high and low dwords of the FILETIME timestamp on success; on failure the outputs are empty and the error flag is set.</p>
  1375. <a name="getfiletimelocal"></a><h4>4.9.3.8 GetFileTimeLocal</h4>
  1376. <pre>localfilename user_var(high dword output) user_var(low dword output)
  1377. </pre>
  1378. <p>This is similar to <a href="Chapter4.html#getfiletime">GetFileTime</a>, only it acts on the system building the installer (it actually compiles into two <a href="Chapter4.html#StrCpy">StrCpy</a> commands). Sets the two output variables with the file timestamp of the file on the build system.</p>
  1379. <a name="getfullpathname"></a><h4>4.9.3.9 GetFullPathName</h4>
  1380. <pre>[/SHORT] user_var(output) path_or_file
  1381. </pre>
  1382. <p>Assign the full path of the file specified to user variable $x. If the path portion of the parameter is not found, the error flag will be set and $x will be empty. If /SHORT is specified, the path is converted to the short filename form. However, if /SHORT is not specified, the path isn't converted to its long filename form. To get the long filename, call GetLongPathName using the System plug-in. Note that GetLongPathName is only available on Windows 98, Windows 2000 and above.</p>
  1383. <pre>StrCpy $INSTDIR $PROGRAMFILES\NSIS
  1384. SetOutPath $INSTDIR
  1385. GetFullPathName $0 ..
  1386. DetailPrint $0 # will print C:\Program Files
  1387. GetFullPathName /SHORT $0 $INSTDIR
  1388. DetailPrint $0 # will print C:\Progra~1\NSIS
  1389. </pre>
  1390. <pre>StrCpy $0 C:\Progra~1\NSIS
  1391. System::Call 'kernel32::GetLongPathName(t r0, t .r1, i ${NSIS_MAX_STRLEN}) i .r2'
  1392. StrCmp $2 error +2
  1393. StrCpy $0 $1
  1394. DetailPrint $0 # will print C:\Program Files\NSIS, where supported
  1395. </pre>
  1396. <a name="gettempfilename"></a><h4>4.9.3.10 GetTempFileName</h4>
  1397. <pre>user_var(output) [base_dir]
  1398. </pre>
  1399. <p>Assign to the user variable $x, the name of a temporary file. The file will be created for you and it will be empty. The name of the temporary file is guaranteed to be unique. If to want the temporary file to be created in another directory other than the Windows temp directory, specify a base_dir. You should <a href="Chapter4.html#delete">Delete</a> the file when you are done with it.</p>
  1400. <pre>GetTempFileName $0
  1401. File /oname=$0 something.dat
  1402. # do something with something.dat
  1403. Delete $0
  1404. </pre>
  1405. <a name="searchpath"></a><h4>4.9.3.11 SearchPath</h4>
  1406. <pre>user_var(output) filename
  1407. </pre>
  1408. <p>Assign to the user variable $x, the full path of the file named by the second parameter. The error flag will be set and $x will be empty if the file cannot be found. Uses <a href="http://msdn.microsoft.com/en-us/library/aa365527">SearchPath()</a> to search the system paths for the file.</p>
  1409. <a name="setfileattributes"></a><h4>4.9.3.12 SetFileAttributes</h4>
  1410. <pre>filename attribute1|attribute2|...
  1411. </pre>
  1412. <p>Sets the file attributes of 'filename'. Valid attributes can be combined with | and are:</p>
  1413. <ul>
  1414. <li><em>NORMAL</em> or <em>FILE_ATTRIBUTE_NORMAL</em> (you can use 0 to abbreviate this)</li><li><em>ARCHIVE</em> or <em>FILE_ATTRIBUTE_ARCHIVE</em></li><li><em>HIDDEN</em> or <em>FILE_ATTRIBUTE_HIDDEN</em></li><li><em>OFFLINE</em> or <em>FILE_ATTRIBUTE_OFFLINE</em></li><li><em>READONLY</em> or <em>FILE_ATTRIBUTE_READONLY</em></li><li><em>SYSTEM</em> or <em>FILE_ATTRIBUTE_SYSTEM</em></li><li><em>TEMPORARY</em> or <em>FILE_ATTRIBUTE_TEMPORARY</em></li></ul>
  1415. <p>The error flag will be set if the file's attributes cannot be set (i.e. the file doesn't exist, or you don't have the right permissions). You can only set attributes. It's not possible to unset them. If you want to remove an attribute use NORMAL. This way all attributes are erased. This command doesn't support wildcards.</p>
  1416. <a name="regdll"></a><h4>4.9.3.13 RegDLL</h4>
  1417. <pre>dllfile [entrypoint_name]
  1418. </pre>
  1419. <p>Loads the specified DLL and calls DllRegisterServer (or entrypoint_name if specified). The error flag is set if an error occurs (i.e. it can't load the DLL, initialize OLE, find the entry point, or the function returned anything other than ERROR_SUCCESS (=0)).</p>
  1420. <p>Use <a href="Chapter4.html#setoutpath">SetOutPath</a> to set the current directory for DLLs that depend on other DLLs that are now in the path or in the Windows directory. For example, if foo.dll depends on bar.dll which is located in $INSTDIR use:</p>
  1421. <pre> SetOutPath $INSTDIR
  1422. RegDLL $INSTDIR\foo.dll
  1423. </pre>
  1424. <a name="unregdll"></a><h4>4.9.3.14 UnRegDLL</h4>
  1425. <pre>dllfile
  1426. </pre>
  1427. <p>Loads the specified DLL and calls DllUnregisterServer. The error flag is set if an error occurs (i.e. it can't load the DLL, initialize OLE, find the entry point, or the function returned anything other than ERROR_SUCCESS (=0)).</p>
  1428. <a name="flowcontrol"></a><h3>4.9.4 Flow Control Instructions</h3>
  1429. <a name="abort"></a><h4>4.9.4.1 Abort</h4>
  1430. <pre>[user_message]
  1431. </pre>
  1432. <p>Cancels the install, stops execution of script, and displays user_message in the status display. Note: you can use this from <a href="Chapter4.html#callbacks">Callback functions</a> to do special things. <a href="Chapter4.html#pages">Page callbacks</a> also uses <a href="Chapter4.html#abort">Abort</a> for special purposes.</p>
  1433. <pre>Abort
  1434. Abort &quot;can't install&quot;
  1435. </pre>
  1436. <a name="call"></a><h4>4.9.4.2 Call</h4>
  1437. <pre>function_name | :label_name | user_var(input)
  1438. </pre>
  1439. <p>Calls the function named <em>function_name</em>, the label named <em>label_name</em>, or a variable that specifies an address. An address is returned by <a href="Chapter4.html#getcurrentaddress">GetCurrentAddress</a>, <a href="Chapter4.html#getfunctionaddress">GetFunctionAddress</a> or <a href="Chapter4.html#getlabeladdress">GetLabelAddress</a>. A call returns when it encounters a <a href="Chapter4.html#return">Return</a> instruction. Sections and functions are automatically ended with a <a href="Chapter4.html#return">Return</a> instruction. Uninstall functions cannot be called from installer functions and sections, and vice-versa.</p>
  1440. <pre>Function func
  1441. Call :label
  1442. DetailPrint &quot;#1: This will only appear 1 time.&quot;
  1443. label:
  1444. DetailPrint &quot;#2: This will appear before and after message #1.&quot;
  1445. Call :.global_label
  1446. FunctionEnd
  1447. Section
  1448. Call func
  1449. Return
  1450. .global_label:
  1451. DetailPrint &quot;#3: The global label was called&quot;
  1452. SectionEnd
  1453. </pre>
  1454. <a name="clearerrors"></a><h4>4.9.4.3 ClearErrors</h4>
  1455. <p>Clears the error flag.</p>
  1456. <pre>ClearErrors
  1457. IfErrors 0 +2
  1458. MessageBox MB_OK &quot;this message box will never show&quot;
  1459. </pre>
  1460. <a name="getcurrentaddress"></a><h4>4.9.4.4 GetCurrentAddress</h4>
  1461. <pre>user_var(output)
  1462. </pre>
  1463. <p>Gets the address of the current instruction (the <a href="Chapter4.html#getcurrentaddress">GetCurrentAddress</a>) and stores it in the output user variable. This user variable then can be passed to <a href="Chapter4.html#call">Call</a> or <a href="Chapter4.html#goto">Goto</a>.</p>
  1464. <pre>Function func
  1465. DetailPrint &quot;function&quot;
  1466. IntOp $0 $0 + 2 ; Calculate the address after of the instruction after &quot;Goto callFunc&quot; in the Section
  1467. Call $0
  1468. DetailPrint &quot;function end&quot;
  1469. FunctionEnd
  1470. Section
  1471. DetailPrint &quot;section&quot;
  1472. GetCurrentAddress $0
  1473. Goto callFunc
  1474. DetailPrint &quot;back in section&quot;
  1475. Return
  1476. callFunc:
  1477. Call func
  1478. DetailPrint &quot;section end&quot;
  1479. SectionEnd
  1480. </pre>
  1481. <a name="getfunctionaddress"></a><h4>4.9.4.5 GetFunctionAddress</h4>
  1482. <pre>user_var(output) function_name
  1483. </pre>
  1484. <p>Gets the address of the function and stores it in the output user variable. This user variable then can be passed to <a href="Chapter4.html#call">Call</a> or <a href="Chapter4.html#goto">Goto</a>. Note that if you <a href="Chapter4.html#goto">Goto</a> an address which is the output of <a href="Chapter4.html#getfunctionaddress">GetFunctionAddress</a>, your function will never be returned to (when the function you Goto'd to returns, you return instantly).</p>
  1485. <pre>Function func
  1486. DetailPrint &quot;function&quot;
  1487. FunctionEnd
  1488. Section
  1489. GetFunctionAddress $0 func
  1490. Call $0
  1491. SectionEnd
  1492. </pre>
  1493. <a name="getlabeladdress"></a><h4>4.9.4.6 GetLabelAddress</h4>
  1494. <pre>user_var(output) label
  1495. </pre>
  1496. <p>Gets the address of the label and stores it in the output user variable. This user variable then can be passed to <a href="Chapter4.html#call">Call</a> or <a href="Chapter4.html#goto">Goto</a>. Note that you may only call this with labels accessible from your function, but you can call it from anywhere (which is potentially dangerous). Note that if you <a href="Chapter4.html#call">Call</a> the output of <a href="Chapter4.html#getlabeladdress">GetLabelAddress</a>, code will be executed until it Return's (explicitly or implicitly at the end of a function), and then you will be returned to the statement after the <a href="Chapter4.html#call">Call</a>.</p>
  1497. <pre>label:
  1498. DetailPrint &quot;label&quot;
  1499. GetLabelAddress $0 label
  1500. IntOp $0 $0 + 4
  1501. Goto $0
  1502. DetailPrint &quot;done&quot;
  1503. </pre>
  1504. <a name="goto"></a><h4>4.9.4.7 Goto</h4>
  1505. <pre>label_to_jump_to | +offset| -offset| user_var(target)
  1506. </pre>
  1507. <p>If label is specified, goto the label 'label_to_jump_to:'.</p>
  1508. <p>If +offset or -offset is specified, jump is relative by offset instructions. Goto +1 goes to the next instruction, Goto -1 goes to the previous instruction, etc.</p>
  1509. <p>If a user variable is specified, jumps to absolute address (generally you will want to get this value from a function like <a href="Chapter4.html#getlabeladdress">GetLabelAddress</a>). Compiler flag commands and <a href="Chapter4.html#ssectionin">SectionIn</a> aren't instructions so jumping over them has no effect.</p>
  1510. <pre>Goto label
  1511. Goto +2
  1512. Goto -2
  1513. Goto $0
  1514. </pre>
  1515. <a name="ifabort"></a><h4>4.9.4.8 IfAbort</h4>
  1516. <pre>label_to_goto_if_abort [label_to_goto_if_no_abort]
  1517. </pre>
  1518. <p>Will &quot;return&quot; true if the installation has been aborted. This can happen if the user chose abort on a file that failed to create (or overwrite) or if the user aborted by hand. This function can only be called from the leave function of the instfiles <a href="Chapter4.html#page">page</a>.</p>
  1519. <pre>Page instfiles &quot;&quot; &quot;&quot; instfilesLeave
  1520. Function instfilesLeave
  1521. IfAbort 0 +2
  1522. MessageBox MB_OK &quot;user aborted&quot;
  1523. FunctionEnd
  1524. </pre>
  1525. <a name="iferrors"></a><h4>4.9.4.9 IfErrors</h4>
  1526. <pre>jumpto_iferror [jumpto_ifnoerror]
  1527. </pre>
  1528. <p>Checks and clears the error flag, and if it is set, it will goto jumpto_iferror, otherwise it will goto jumpto_ifnoerror. The error flag is set by other instructions when a recoverable error (such as trying to delete a file that is in use) occurs.</p>
  1529. <pre>ClearErrors
  1530. File file.dat
  1531. IfErrors 0 +2
  1532. Call ErrorHandler
  1533. </pre>
  1534. <a name="iffileexists"></a><h4>4.9.4.10 IfFileExists</h4>
  1535. <pre>file_to_check_for jump_if_present [jump_otherwise]
  1536. </pre>
  1537. <p>Checks for existence of file(s) file_to_check_for (which can be a wildcard, or a directory), and Gotos jump_if_present if the file exists, otherwise Gotos jump_otherwise. If you want to check to see if a file is a directory, use <a href="Chapter4.html#iffileexists">IfFileExists</a> DIRECTORY\*.*</p>
  1538. <pre>IfFileExists $WINDIR\notepad.exe 0 +2
  1539. MessageBox MB_OK &quot;notepad is installed&quot;
  1540. </pre>
  1541. <a name="ifrebootflag"></a><h4>4.9.4.11 IfRebootFlag</h4>
  1542. <pre>jump_if_set [jump_if_not_set]
  1543. </pre>
  1544. <p>Checks the reboot flag, and jumps to jump_if_set if the reboot flag is set, otherwise jumps to jump_if_not_set. The reboot flag can be set by <a href="Chapter4.html#delete">Delete</a> and <a href="Chapter4.html#rename">Rename</a>, or manually with <a href="Chapter4.html#setrebootflag">SetRebootFlag</a>.</p>
  1545. <pre>IfRebootFlag 0 noreboot
  1546. MessageBox MB_YESNO &quot;A reboot is required to finish the installation. Do you wish to reboot now?&quot; IDNO noreboot
  1547. Reboot
  1548. noreboot:
  1549. </pre>
  1550. <a name="ifsilent"></a><h4>4.9.4.12 IfSilent</h4>
  1551. <pre>jump_if_silent [jump_if_not]
  1552. </pre>
  1553. <p>Checks the silent flag, and jumps to jump_if_silent if the installer is silent, otherwise jumps to jump_if_not. The silent flag can be set by <a href="Chapter4.html#asilentinstall">SilentInstall</a>, <a href="Chapter4.html#asilentuninstall">SilentUninstall</a>, <a href="Chapter4.html#setsilent">SetSilent</a> and by the user passing /S on the command line.</p>
  1554. <pre>IfSilent +2
  1555. ExecWait '&quot;$INSTDIR\nonsilentprogram.exe&quot;'
  1556. </pre>
  1557. <a name="intcmp"></a><h4>4.9.4.13 IntCmp</h4>
  1558. <pre>val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]
  1559. </pre>
  1560. <p>Compares two integers val1 and val2. If val1 and val2 are equal, Gotos jump_if_equal, otherwise if val1 &lt; val2, Gotos jump_if_val1_less, otherwise if val1 &gt; val2, Gotos jump_if_val1_more.</p>
  1561. <pre>IntCmp $0 5 is5 lessthan5 morethan5
  1562. is5:
  1563. DetailPrint &quot;$$0 == 5&quot;
  1564. Goto done
  1565. lessthan5:
  1566. DetailPrint &quot;$$0 &lt; 5&quot;
  1567. Goto done
  1568. morethan5:
  1569. DetailPrint &quot;$$0 &gt; 5&quot;
  1570. Goto done
  1571. done:
  1572. </pre>
  1573. <a name="intcmpu"></a><h4>4.9.4.14 IntCmpU</h4>
  1574. <pre>val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]
  1575. </pre>
  1576. <p>Same as <a href="Chapter4.html#intcmp">IntCmp</a>, but treats the values as unsigned integers.</p>
  1577. <a name="messagebox"></a><h4>4.9.4.15 MessageBox</h4>
  1578. <pre>mb_option_list messagebox_text [/SD return] [return_check jumpto] [return_check_2 jumpto_2]
  1579. </pre>
  1580. <p>Displays a <a href="Chapter4.html#messagebox">MessageBox</a> containing the text &quot;messagebox_text&quot;. mb_option_list must be one or more of the following, delimited by |s (e.g. MB_YESNO|MB_ICONSTOP).</p>
  1581. <ul>
  1582. <li><em>MB_OK</em> - Display with an OK button</li><li><em>MB_OKCANCEL</em> - Display with an OK and a cancel button</li><li><em>MB_ABORTRETRYIGNORE</em> - Display with abort, retry, ignore buttons</li><li><em>MB_RETRYCANCEL</em> - Display with retry and cancel buttons</li><li><em>MB_YESNO</em> - Display with yes and no buttons</li><li><em>MB_YESNOCANCEL</em> - Display with yes, no, cancel buttons</li><li><em>MB_ICONEXCLAMATION</em> - Display with exclamation icon</li><li><em>MB_ICONINFORMATION</em> - Display with information icon</li><li><em>MB_ICONQUESTION</em> - Display with question mark icon</li><li><em>MB_ICONSTOP</em> - Display with stop icon</li><li><em>MB_USERICON</em> - Display with installer's icon</li><li><em>MB_TOPMOST</em> - Make messagebox topmost</li><li><em>MB_SETFOREGROUND</em> - Set foreground</li><li><em>MB_RIGHT</em> - Right align text</li><li><em>MB_RTLREADING</em> - RTL reading order</li><li><em>MB_DEFBUTTON1</em> - Button 1 is default</li><li><em>MB_DEFBUTTON2</em> - Button 2 is default</li><li><em>MB_DEFBUTTON3</em> - Button 3 is default</li><li><em>MB_DEFBUTTON4</em> - Button 4 is default</li></ul>
  1583. <p>Return_check can be 0 (or empty, or left off), or one of the following:</p>
  1584. <ul>
  1585. <li><em>IDABORT</em> - Abort button</li><li><em>IDCANCEL</em> - Cancel button</li><li><em>IDIGNORE</em> - Ignore button</li><li><em>IDNO</em> - No button</li><li><em>IDOK</em> - OK button</li><li><em>IDRETRY</em> - Retry button</li><li><em>IDYES</em> - Yes button</li></ul>
  1586. <p>If the return value of the <a href="Chapter4.html#messagebox">MessageBox</a> is return_check, the installer will Goto jumpto.</p>
  1587. <p>Use the /SD parameter with one of the return_check values above to specify the option that will be used when the installer is silent. See <a href="Chapter4.html#silent">section 4.12</a> for more information.</p>
  1588. <pre>MessageBox MB_OK &quot;simple message box&quot;
  1589. MessageBox MB_YESNO &quot;is it true?&quot; IDYES true IDNO false
  1590. true:
  1591. DetailPrint &quot;it's true!&quot;
  1592. Goto next
  1593. false:
  1594. DetailPrint &quot;it's false&quot;
  1595. next:
  1596. MessageBox MB_YESNO &quot;is it true? (defaults to yes on silent installations)&quot; /SD IDYES IDNO false2
  1597. DetailPrint &quot;it's true (or silent)!&quot;
  1598. Goto next2
  1599. false2:
  1600. DetailPrint &quot;it's false&quot;
  1601. next2:
  1602. </pre>
  1603. <a name="return"></a><h4>4.9.4.16 Return</h4>
  1604. <p>Returns from a function or section.</p>
  1605. <pre>Function func
  1606. StrCmp $0 &quot;return now&quot; 0 +2
  1607. Return
  1608. # do stuff
  1609. FunctionEnd
  1610. Section
  1611. Call func
  1612. ;&quot;Return&quot; will return here
  1613. SectionEnd
  1614. </pre>
  1615. <a name="quit"></a><h4>4.9.4.17 Quit</h4>
  1616. <p>Causes the installer to exit as soon as possible. After <a href="Chapter4.html#quit">Quit</a> is called, the installer will exit (no callback functions will get a chance to run).</p>
  1617. <a name="seterrors"></a><h4>4.9.4.18 SetErrors</h4>
  1618. <p>Sets the error flag.</p>
  1619. <pre>SetErrors
  1620. IfErrors 0 +2
  1621. MessageBox MB_OK &quot;this message box will always show&quot;
  1622. </pre>
  1623. <a name="strcmp"></a><h4>4.9.4.19 StrCmp</h4>
  1624. <pre>str1 str2 jump_if_equal [jump_if_not_equal]
  1625. </pre>
  1626. <p>Compares (case insensitively) str1 to str2. If str1 and str2 are equal, Gotos jump_if_equal, otherwise Gotos jump_if_not_equal.</p>
  1627. <pre>StrCmp $0 &quot;a string&quot; 0 +3
  1628. DetailPrint '$$0 == &quot;a string&quot;'
  1629. Goto +2
  1630. DetailPrint '$$0 != &quot;a string&quot;'
  1631. </pre>
  1632. <a name="strcmps"></a><h4>4.9.4.20 StrCmpS</h4>
  1633. <pre>str1 str2 jump_if_equal [jump_if_not_equal]
  1634. </pre>
  1635. <p>Same as <a href="Chapter4.html#strcmp">StrCmp</a>, but case sensitive.</p>
  1636. <a name="fileinst"></a><h3>4.9.5 File Instructions</h3>
  1637. <a name="FileClose"></a><h4>4.9.5.1 FileClose</h4>
  1638. <pre>handle
  1639. </pre>
  1640. <p>Closes a file handle opened with <a href="Chapter4.html#FileOpen">FileOpen</a>.</p>
  1641. <a name="FileOpen"></a><h4>4.9.5.2 FileOpen</h4>
  1642. <pre>user_var(handle output) filename openmode
  1643. </pre>
  1644. <p>Opens a file named &quot;filename&quot; and sets the handle output variable with the handle. The openmode should be one of &quot;r&quot; (read) &quot;w&quot; (write, all contents of file are destroyed) or &quot;a&quot; (append, meaning opened for both read and write, contents preserved). In all open modes, the file pointer is placed at the beginning of the file. If the file cannot be opened the handle output is set to empty and the error flag is set.</p>
  1645. <p>If no absolute path is specified the current folder will be used. The current folder is the folder set using the last <a href="Chapter4.html#setoutpath">SetOutPath</a> instruction. If you have not used <a href="Chapter4.html#setoutpath">SetOutPath</a> the current folder is <a href="Chapter4.html#varother">$EXEDIR</a>.</p>
  1646. <pre>FileOpen $0 $INSTDIR\file.dat r
  1647. FileClose $0
  1648. </pre>
  1649. <a name="FileRead"></a><h4>4.9.5.3 FileRead</h4>
  1650. <pre>handle user_var(output) [maxlen]
  1651. </pre>
  1652. <p>Reads a string (ANSI characters) from a file opened with <a href="Chapter4.html#FileOpen">FileOpen</a>. The string is read until either a newline (or carriage return newline pair) occurs, or until a null byte is read, or until maxlen is met (if specified). By default, strings are limited to 1024 characters (a special build with larger NSIS_MAX_STRLEN can be compiled or downloaded). If the end of file is reached and no more data is available, the output string will be empty and the error flag will be set.</p>
  1653. <p><div class="wb"> <b>Unicode: </b> DBCS text is supported but conversion output is limited to UCS-2/BMP, surrogate pairs are not supported. The system default ANSI codepage (ACP) is used during the conversion. </div></p>
  1654. <pre>ClearErrors
  1655. FileOpen $0 $INSTDIR\file.dat r
  1656. IfErrors done
  1657. FileRead $0 $1
  1658. DetailPrint $1
  1659. FileClose $0
  1660. done:
  1661. </pre>
  1662. <a name="FileReadUTF16LE"></a><h4>4.9.5.4 FileReadUTF16LE</h4>
  1663. <pre>handle user_var(output) [maxlen]
  1664. </pre>
  1665. <p>This function is only available when building a <a href="Chapter1.html#intro-unicode">Unicode installer</a>.</p>
  1666. <p>Reads a string (UTF-16LE characters) from a file opened with <a href="Chapter4.html#FileOpen">FileOpen</a>. The string is read until either a newline (or carriage return newline pair) occurs, or until a null wide-character is read, or until maxlen is met (if specified). By default, strings are limited to 1024 characters (a special build with larger NSIS_MAX_STRLEN can be compiled or downloaded). If the end of file is reached and no more data is available, the output string will be empty and the error flag will be set. If present, the BOM at the start of the file is skipped.</p>
  1667. <pre>ClearErrors
  1668. FileOpen $0 $INSTDIR\file.dat r
  1669. IfErrors done
  1670. FileReadUTF16LE $0 $1
  1671. DetailPrint $1
  1672. FileClose $0
  1673. done:
  1674. </pre>
  1675. <a name="FileReadByte"></a><h4>4.9.5.5 FileReadByte</h4>
  1676. <pre>handle user_var(output)
  1677. </pre>
  1678. <p>Reads a byte from a file opened with <a href="Chapter4.html#FileOpen">FileOpen</a>. The byte is stored in the output as an integer (0-255). If the end of file is reached and no more data is available, the output will be empty and the error flag will be set.</p>
  1679. <pre>ClearErrors
  1680. FileOpen $0 $INSTDIR\file.dat r
  1681. IfErrors done
  1682. FileReadByte $0 $1
  1683. FileReadByte $0 $2
  1684. DetailPrint &quot;$1 $2&quot;
  1685. FileClose $0
  1686. done:
  1687. </pre>
  1688. <a name="FileReadWord"></a><h4>4.9.5.6 FileReadWord</h4>
  1689. <pre>handle user_var(output)
  1690. </pre>
  1691. <p>This function is only available when building a <a href="Chapter1.html#intro-unicode">Unicode installer</a>.</p>
  1692. <p>Reads a word (2-bytes) from a file opened with <a href="Chapter4.html#FileOpen">FileOpen</a>. The word is stored in the output as an integer (0-65535). If the end of file is reached and no more data is available, the output will be empty and the error flag will be set.</p>
  1693. <pre>ClearErrors
  1694. FileOpen $0 $INSTDIR\file.dat r
  1695. IfErrors done
  1696. FileReadWord $0 $1
  1697. FileReadWord $0 $2
  1698. DetailPrint &quot;$1 $2&quot;
  1699. FileClose $0
  1700. done:
  1701. </pre>
  1702. <a name="FileSeek"></a><h4>4.9.5.7 FileSeek</h4>
  1703. <pre>handle offset [mode] [user_var(new position)]
  1704. </pre>
  1705. <p>Seeks a file opened with <a href="Chapter4.html#FileOpen">FileOpen</a>. If mode is omitted or specified as SET, the file is positioned to &quot;offset&quot;, relative to the beginning of the file. If mode is specified as CUR, then the file is positioned to &quot;offset&quot;, relative to the current file position. If mode is specified as END, then the file is positioned to &quot;offset&quot;, relative to the end of the file. If the final parameter &quot;new position&quot; is specified, the new file position will be stored in that variable.</p>
  1706. <pre>ClearErrors
  1707. FileOpen $0 $INSTDIR\file.dat r
  1708. IfErrors done
  1709. FileSeek $0 -5 END
  1710. FileRead $0 $1
  1711. DetailPrint $1
  1712. FileClose $0
  1713. done:
  1714. </pre>
  1715. <a name="FileWrite"></a><h4>4.9.5.8 FileWrite</h4>
  1716. <pre>handle string
  1717. </pre>
  1718. <p>Writes an ANSI string to a file opened with <a href="Chapter4.html#FileOpen">FileOpen</a>. If an error occurs writing, the error flag will be set.</p>
  1719. <p>(If you are building a <a href="Chapter1.html#intro-unicode">Unicode installer</a>, the function converts the string to ANSI/MBCS. The system default ANSI codepage (ACP) is used during the conversion)</p>
  1720. <pre>ClearErrors
  1721. FileOpen $0 $INSTDIR\file.dat w
  1722. IfErrors done
  1723. FileWrite $0 &quot;some text&quot;
  1724. FileClose $0
  1725. done:
  1726. </pre>
  1727. <a name="FileWriteUTF16LE"></a><h4>4.9.5.9 FileWriteUTF16LE</h4>
  1728. <pre>[/BOM] handle string
  1729. </pre>
  1730. <p>This function is only available when building a <a href="Chapter1.html#intro-unicode">Unicode installer</a>.</p>
  1731. <p>Writes a Unicode (UTF-16LE) string to a file opened with <a href="Chapter4.html#FileOpen">FileOpen</a>. If an error occurs, the error flag will be set. A BOM can be added to empty files with /BOM.</p>
  1732. <pre>ClearErrors
  1733. FileOpen $0 $INSTDIR\file.dat w
  1734. IfErrors done
  1735. FileWriteUTF16LE $0 &quot;some text&quot;
  1736. FileClose $0
  1737. done:
  1738. </pre>
  1739. <a name="FileWriteByte"></a><h4>4.9.5.10 FileWriteByte</h4>
  1740. <pre>handle string
  1741. </pre>
  1742. <p>Writes the integer interpretation of 'string' to a file opened with <a href="Chapter4.html#FileOpen">FileOpen</a>. The error flag is set if an error occurs while writing. The following code writes a &quot;Carriage Return / Line Feed&quot; pair to the file.</p>
  1743. <pre>FileWriteByte file_handle &quot;13&quot;
  1744. FileWriteByte file_handle &quot;10&quot;
  1745. </pre>
  1746. <p>Note that only the low byte of the integer is used, i.e. writing 256 is the same as writing 0, etc.</p>
  1747. <a name="FileWriteWord"></a><h4>4.9.5.11 FileWriteWord</h4>
  1748. <pre>handle string
  1749. </pre>
  1750. <p>This function is only available when building a <a href="Chapter1.html#intro-unicode">Unicode installer</a>.</p>
  1751. <p>Writes the integer interpretation of 'string' as a WORD (2-bytes, range: 0-65535) to a file opened with <a href="Chapter4.html#FileOpen">FileOpen</a>. The error flag is set if an error occurs while writing. The following code writes a &quot;Carriage Return / Line Feed&quot; pair to the file.</p>
  1752. <pre>FileWriteWord file_handle &quot;13&quot;
  1753. FileWriteWord file_handle &quot;10&quot;
  1754. </pre>
  1755. <p>Note that only the low WORD of the integer is used, i.e. writing 65536 is the same as writing 0, etc.</p>
  1756. <a name="FindClose"></a><h4>4.9.5.12 FindClose</h4>
  1757. <pre>handle
  1758. </pre>
  1759. <p>Closes a search opened with <a href="Chapter4.html#FindFirst">FindFirst</a>.</p>
  1760. <a name="FindFirst"></a><h4>4.9.5.13 FindFirst</h4>
  1761. <pre>user_var(handle output) user_var(filename output) filespec
  1762. </pre>
  1763. <p>Performs a search for 'filespec', placing the first file found in filename_output (a user variable). It also puts the handle of the search into handle_output (also a user variable). If no files are found, both outputs are set to empty and the error flag is set. <a href="Chapter4.html#FindClose">FindClose</a> must be used to close the handle. Note that the filename output is without path.</p>
  1764. <pre>FindFirst $0 $1 $INSTDIR\*.txt
  1765. loop:
  1766. StrCmp $1 &quot;&quot; done
  1767. DetailPrint $1
  1768. FindNext $0 $1
  1769. Goto loop
  1770. done:
  1771. FindClose $0
  1772. </pre>
  1773. <a name="FindNext"></a><h4>4.9.5.14 FindNext</h4>
  1774. <pre>handle user_var(filename_output)
  1775. </pre>
  1776. <p>Continues a search began with <a href="Chapter4.html#FindFirst">FindFirst</a>. handle should be the handle_output_variable returned by <a href="Chapter4.html#FindFirst">FindFirst</a>. If the search is completed (there are no more files), filename_output is set to empty and the error flag is set. Note that the filename output is without path.</p>
  1777. <a name="uninst"></a><h3>4.9.6 Uninstaller Instructions</h3>
  1778. <a name="writeuninstaller"></a><h4>4.9.6.1 WriteUninstaller</h4>
  1779. <pre>[Path\]exename.exe
  1780. </pre>
  1781. <p>Writes the uninstaller to the filename (and optionally path) specified. Only valid from within an install section or function and requires that you have an uninstall section in your script. You can call this one or more times to write out one or more copies of the uninstaller.</p>
  1782. <pre>WriteUninstaller $INSTDIR\uninstaller.exe
  1783. </pre>
  1784. <a name="miscinst"></a><h3>4.9.7 Miscellaneous Instructions</h3>
  1785. <a name="geterrorlevel"></a><h4>4.9.7.1 GetErrorLevel</h4>
  1786. <pre>user_var(error level output)
  1787. </pre>
  1788. <p>Returns the last error level set by <a href="Chapter4.html#seterrorlevel">SetErrorLevel</a> or -1 if it has never been set.</p>
  1789. <pre>GetErrorLevel $0
  1790. IntOp $0 $0 + 1
  1791. SetErrorLevel $0
  1792. </pre>
  1793. <a name="getinstdirerror"></a><h4>4.9.7.2 GetInstDirError</h4>
  1794. <pre>user_var(error output)
  1795. </pre>
  1796. <p>Use in the leave function of a directory page. Reads the flag set if '<a href="Chapter4.html#adirverify">DirVerify leave</a>' is used. Possible values:</p>
  1797. <p>0: No error</p>
  1798. <p>1: Invalid installation directory</p>
  1799. <p>2: Not enough space on installation drive</p>
  1800. <pre>!include LogicLib.nsh
  1801. PageEx directory
  1802. DirVerify leave
  1803. PageCallbacks &quot;&quot; &quot;&quot; dirLeave
  1804. PageExEnd
  1805. Function dirLeave
  1806. GetInstDirError $0
  1807. ${Switch} $0
  1808. ${Case} 0
  1809. MessageBox MB_OK &quot;valid installation directory&quot;
  1810. ${Break}
  1811. ${Case} 1
  1812. MessageBox MB_OK &quot;invalid installation directory!&quot;
  1813. Abort
  1814. ${Break}
  1815. ${Case} 2
  1816. MessageBox MB_OK &quot;not enough free space!&quot;
  1817. Abort
  1818. ${Break}
  1819. ${EndSwitch}
  1820. FunctionEnd
  1821. </pre>
  1822. <a name="initpluginsdir"></a><h4>4.9.7.3 InitPluginsDir</h4>
  1823. <p>Initializes the plug-ins dir (<a href="Chapter4.html#varconstant">$PLUGINSDIR</a>) if not already initialized.</p>
  1824. <pre>InitPluginsDir
  1825. File /oname=$PLUGINSDIR\image.bmp image.bmp
  1826. </pre>
  1827. <a name="nop"></a><h4>4.9.7.4 Nop</h4>
  1828. <p>Does nothing.</p>
  1829. <a name="seterrorlevel"></a><h4>4.9.7.5 SetErrorLevel</h4>
  1830. <pre>error_level
  1831. </pre>
  1832. <p>Sets the error level of the installer or uninstaller to <em>error_level</em>. See <a href="AppendixD.html#errorlevels">Error Levels</a> for more information.</p>
  1833. <pre>IfRebootFlag 0 +2
  1834. SetErrorLevel 4
  1835. </pre>
  1836. <a name="setshellvarcontext"></a><h4>4.9.7.6 SetShellVarContext</h4>
  1837. <pre><b>current</b>|all
  1838. </pre>
  1839. <p>Sets the context of $SMPROGRAMS and other shell folders. If set to 'current' (the default), the current user's shell folders are used. If set to 'all', the 'all users' shell folder is used. The all users folder may not be supported on all OSes. If the all users folder is not found, the current user folder will be used. Please take into consideration that a &quot;normal user&quot; has no rights to write in the all users area. Only admins have full access rights to the all users area. You can check this by using the UserInfo plug-in. See Contrib\UserInfo\UserInfo.nsi for an example.</p>
  1840. <p>Note that, if used in installer code, this will only affect the installer, and if used in uninstaller code, this will only affect the uninstaller. To affect both, it needs to be used in both.</p>
  1841. <pre>SetShellVarContext current
  1842. StrCpy $0 $DESKTOP
  1843. SetShellVarContext all
  1844. StrCpy $1 $DESKTOP
  1845. MessageBox MB_OK $0$\n$1
  1846. </pre>
  1847. <a name="sleep"></a><h4>4.9.7.7 Sleep</h4>
  1848. <pre>sleeptime_in_ms
  1849. </pre>
  1850. <p>Pauses execution in the installer for sleeptime_in_ms milliseconds. sleeptime_in_ms can be a variable, e.g. &quot;$0&quot; or a number, i.e. &quot;666&quot;.</p>
  1851. <pre>DetailPrint &quot;sleeping...&quot;
  1852. Sleep 3000
  1853. DetailPrint &quot;back to work&quot;
  1854. </pre>
  1855. <a name="stringinst"></a><h3>4.9.8 String Manipulation Instructions</h3>
  1856. <a name="StrCpy"></a><h4>4.9.8.1 StrCpy</h4>
  1857. <pre>user_var(destination) str [maxlen] [start_offset]
  1858. </pre>
  1859. <p>Sets the user variable $x with str. str can contain variables (including the user variable being set (concatenating strings this way is possible, etc)). If maxlen is specified, the string will be a maximum of maxlen characters (if maxlen is negative, the string will be truncated abs(maxlen) characters from the end). If start_offset is specified, the source is offset by it (if start_offset is negative, it will start abs(start_offset) from the end of the string).</p>
  1860. <pre>StrCpy $0 &quot;a string&quot; # = &quot;a string&quot;
  1861. StrCpy $0 &quot;a string&quot; 3 # = &quot;a s&quot;
  1862. StrCpy $0 &quot;a string&quot; -1 # = &quot;a strin&quot;
  1863. StrCpy $0 &quot;a string&quot; &quot;&quot; 2 # = &quot;string&quot;
  1864. StrCpy $0 &quot;a string&quot; &quot;&quot; -3 # = &quot;ing&quot;
  1865. StrCpy $0 &quot;a string&quot; 3 -4 # = &quot;rin&quot;
  1866. StrCpy $0 &quot;$0$0&quot; # = &quot;rinrin&quot;
  1867. </pre>
  1868. <a name="StrLen"></a><h4>4.9.8.2 StrLen</h4>
  1869. <pre>user_var(length output) str
  1870. </pre>
  1871. <p>Sets user variable $x to the length of str.</p>
  1872. <pre>StrLen $0 &quot;123456&quot; # = 6
  1873. </pre>
  1874. <a name="stackinst"></a><h3>4.9.9 Stack Support</h3>
  1875. <a name="Exch"></a><h4>4.9.9.1 Exch</h4>
  1876. <pre>[user_var | stack_index]
  1877. </pre>
  1878. <p>When no parameter is specified, exchanges the top two elements of the stack. When a parameter is specified and is a user variable, exchanges the top element of the stack with the parameter. When a parameter is specified and is a positive integer, <a href="Chapter4.html#Exch">Exch</a> will swap the item on the top of the stack with the item that is specified by the offset from the top of the stack in the parameter. If there are not enough items on the stack to accomplish the exchange, a fatal error will occur (to help you debug your code :).</p>
  1879. <pre>Push 1
  1880. Push 2
  1881. Exch
  1882. Pop $0 # = 1
  1883. </pre>
  1884. <pre>Push 1
  1885. Push 2
  1886. Push 3
  1887. Exch 2
  1888. Pop $0 # = 1
  1889. </pre>
  1890. <pre>StrCpy $0 1
  1891. Push 2
  1892. Exch $0 # = 2
  1893. Pop $1 # = 1
  1894. </pre>
  1895. <a name="Pop"></a><h4>4.9.9.2 Pop</h4>
  1896. <pre>user_var(out)
  1897. </pre>
  1898. <p>Pops a string off of the stack into user variable $x. If the stack is empty, the error flag will be set.</p>
  1899. <pre>Push 1
  1900. Pop $0 # = 1
  1901. </pre>
  1902. <a name="Push"></a><h4>4.9.9.3 Push</h4>
  1903. <pre>string
  1904. </pre>
  1905. <p>Pushes a string onto the stack. The string can then be Pop'ed off of the stack.</p>
  1906. <pre>Push &quot;a string&quot;
  1907. </pre>
  1908. <a name="intinst"></a><h3>4.9.10 Integer Support</h3>
  1909. <a name="intfmt"></a><h4>4.9.10.1 IntFmt</h4>
  1910. <pre>user_var(output) format numberstring
  1911. </pre>
  1912. <p>Formats the number in &quot;numberstring&quot; using the format &quot;format&quot;, and sets the output to user variable $x. Example format strings include &quot;%08X&quot; &quot;%u&quot;</p>
  1913. <pre>IntFmt $0 &quot;0x%08X&quot; 195948557
  1914. IntFmt $0 &quot;%c&quot; 0x41
  1915. </pre>
  1916. <a name="intop"></a><h4>4.9.10.2 IntOp</h4>
  1917. <pre>user_var(output) value1 OP [value2]
  1918. </pre>
  1919. <p>Combines value1 and (depending on OP) value2 into the specified user variable (<code>user_var</code>). OP is defined as one of the following:</p>
  1920. <ul>
  1921. <li><em>+</em> ADDs value1 and value2</li><li><em>-</em> SUBTRACTs value2 from value1</li><li><em>*</em> MULTIPLIEs value1 and value2</li><li><em>/</em> DIVIDEs value1 by value2</li><li><em>%</em> MODULUSs value1 by value2</li><li><em>|</em> BINARY ORs value1 and value2</li><li><em>&amp;</em> BINARY ANDs value1 and value2</li><li><em>^</em> BINARY XORs value1 and value2</li><li><em>&gt;&gt;</em> RIGHT SHIFTs value1 by value2</li><li><em>&lt;&lt;</em> LEFT SHIFTs value1 by value2</li><li><em>~</em> BITWISE NEGATEs value1 (i.e. 7 becomes 4294967288)</li><li><em>!</em> LOGICALLY NEGATEs value1 (i.e. 7 becomes 0)</li><li><em>||</em> LOGICALLY ORs value1 and value2</li><li><em>&amp;&amp;</em> LOGICALLY ANDs value1 and value2</li></ul>
  1922. <pre>IntOp $0 1 + 1
  1923. IntOp $0 $0 + 1
  1924. IntOp $0 $0 &lt;&lt; 2
  1925. IntOp $0 $0 ~
  1926. IntOp $0 $0 &amp; 0xF
  1927. </pre>
  1928. <a name="rebootinst"></a><h3>4.9.11 Reboot Instructions</h3>
  1929. <a name="reboot"></a><h4>4.9.11.1 Reboot</h4>
  1930. <p>Reboots the computer. Be careful with this one. If it fails, <a href="Chapter4.html#onrebootfailed">.onRebootFailed</a> is called. In any case, this instruction never returns, just like <a href="Chapter4.html#quit">Quit</a>.</p>
  1931. <pre>MessageBox MB_YESNO|MB_ICONQUESTION &quot;Do you wish to reboot the system?&quot; IDNO +2
  1932. Reboot
  1933. </pre>
  1934. <a name="setrebootflag"></a><h4>4.9.11.2 SetRebootFlag</h4>
  1935. <pre>true|false
  1936. </pre>
  1937. <p>Sets the reboot flag to either true or false. The flag's value can be read using <a href="Chapter4.html#ifrebootflag">IfRebootFlag</a>.</p>
  1938. <pre>SetRebootFlag true
  1939. IfRebootFlag 0 +2
  1940. MessageBox MB_OK &quot;this message box will always show&quot;
  1941. </pre>
  1942. <a name="installlog"></a><h3>4.9.12 Install Logging Instructions</h3>
  1943. <a name="logset"></a><h4>4.9.12.1 LogSet</h4>
  1944. <pre>on|<b>off</b>
  1945. </pre>
  1946. <p>Sets whether install logging to $INSTDIR\install.log will happen. $INSTDIR must have a value before you call this function or it will not work. Note that the <em>NSIS_CONFIG_LOG</em> build setting must be set (<code>scons NSIS_CONFIG_LOG=yes</code>) when building (it is not set by default) to support this. See <a href="AppendixG.html#build">Building NSIS</a> for more information about recompiling NSIS.</p>
  1947. <a name="logtext"></a><h4>4.9.12.2 LogText</h4>
  1948. <pre>text
  1949. </pre>
  1950. <p>If installer logging is enabled, inserts text &quot;text&quot; into the log file.</p>
  1951. <pre>IfFileExists $WINDIR\notepad.exe 0 +2
  1952. LogText &quot;$$WINDIR\notepad.exe exists&quot;
  1953. </pre>
  1954. <a name="secmanage"></a><h3>4.9.13 Section Management</h3>
  1955. <a name="sectionsetflags"></a><h4>4.9.13.1 SectionSetFlags</h4>
  1956. <pre>section_index section_flags
  1957. </pre>
  1958. <p>Sets the section's flags. The flag is a 32-bit integer. The first bit (lowest) represents whether the section is currently selected, the second bit represents whether the section is a section group (don't modify this unless you really know what you are doing), the third bit represents whether the section is a section group end (again, don't modify), the fourth bit represents whether the section is shown in bold or not, the fifth bit represents whether the section is read-only, the sixth bit represents whether the section group is to be automatically expanded, the seventh bit is set for section groups which are partially selected, the eighth bit is internally used for partially selected section group toggling and the ninth bit is used for reflecting section name changes. The error flag will be set if an out of range section is specified.</p>
  1959. <p>Each flag has a name, prefixed with `SF_`:</p>
  1960. <pre>!define SF_SELECTED 1
  1961. !define SF_SECGRP 2
  1962. !define SF_SECGRPEND 4
  1963. !define SF_BOLD 8
  1964. !define SF_RO 16
  1965. !define SF_EXPAND 32
  1966. !define SF_PSELECTED 64
  1967. </pre>
  1968. <p>For an example of usage please see the <a href="../Examples/one-section.nsi">one-section.nsi</a> example.</p>
  1969. <p>For more useful macros and definitions, see Include\Sections.nsh.</p>
  1970. <pre>Section test test_section_id
  1971. SectionEnd
  1972. Function .onInit
  1973. # set section 'test' as selected and read-only
  1974. IntOp $0 ${SF_SELECTED} | ${SF_RO}
  1975. SectionSetFlags ${test_section_id} $0
  1976. FunctionEnd
  1977. </pre>
  1978. <a name="sectiongetflags"></a><h4>4.9.13.2 SectionGetFlags</h4>
  1979. <pre>section_index user_var(output)
  1980. </pre>
  1981. <p>Retrieves the section's flags. See SectionSetFlags for a description of the flags. The error flag will be set if an out of range section is specified.</p>
  1982. <pre>Section test test_section_id
  1983. SectionEnd
  1984. Function .onSelChange
  1985. # keep section 'test' selected
  1986. SectionGetFlags ${test_section_id} $0
  1987. IntOp $0 $0 | ${SF_SELECTED}
  1988. SectionSetFlags ${test_section_id} $0
  1989. FunctionEnd
  1990. </pre>
  1991. <a name="sectionsettext"></a><h4>4.9.13.3 SectionSetText</h4>
  1992. <pre>section_index section_text
  1993. </pre>
  1994. <p>Sets the description for the section section_index. If the text is set to &quot;&quot; then the section will be hidden. The error flag will be set if an out of range section is specified.</p>
  1995. <pre>Section &quot;&quot; test_section_id
  1996. SectionEnd
  1997. Function .onInit
  1998. # change section's name to $WINDIR
  1999. SectionSetText ${test_section_id} $WINDIR
  2000. FunctionEnd
  2001. </pre>
  2002. <a name="sectiongettext"></a><h4>4.9.13.4 SectionGetText</h4>
  2003. <pre>section_index user_var(output)
  2004. </pre>
  2005. <p>Stores the text description of the section section_index into the output. If the section is hidden, stores an empty string. The error flag will be set if an out of range section is specified.</p>
  2006. <pre>Section test test_section_id
  2007. SectionEnd
  2008. Function .onInit
  2009. # append $WINDIR to section's name
  2010. SectionGetText ${test_section_id} $0
  2011. StrCpy $0 &quot;$0 - $WINDIR&quot;
  2012. SectionSetText ${test_section_id} $0
  2013. FunctionEnd
  2014. </pre>
  2015. <a name="sectionsetinsttypes"></a><h4>4.9.13.5 SectionSetInstTypes</h4>
  2016. <pre>section_index inst_types
  2017. </pre>
  2018. <p>Sets the install types the section specified by section_index defaults to the enabled state in. Note that the section index starts with zero. Every bit of inst_types is a flag that tells if the section is in that install type or not. For example, if you have 3 install types and you want the first section to be included in install types 1 and 3, then the command should look like this:</p>
  2019. <pre>SectionSetInstTypes 0 5
  2020. </pre>
  2021. <p>because the binary value for 5 is &quot;...00101&quot;. The error flag will be set if the section index specified is out of range.</p>
  2022. <pre>Section test test_section_id
  2023. SectionEnd
  2024. Function .onInit
  2025. # associate section 'test' with installation types 3 and 4
  2026. SectionSetInstTypes ${test_section_id} 12
  2027. FunctionEnd
  2028. </pre>
  2029. <a name="sectiongetinsttypes"></a><h4>4.9.13.6 SectionGetInstTypes</h4>
  2030. <pre>section_index user_var(output)
  2031. </pre>
  2032. <p>Retrieves the install types flags array of a section. See above explanation about <a href="Chapter4.html#sectionsetinsttypes">SectionSetInstTypes</a> for a description of how to deal with the output. The error flag will be set if the section index is out of range.</p>
  2033. <pre>Section test test_section_id
  2034. SectionEnd
  2035. Function .onInit
  2036. # associate section 'test' with installation types 5, on top of its existing associations
  2037. SectionGetInstTypes ${test_section_id} $0
  2038. IntOp $0 $0 | 16
  2039. SectionSetInstTypes ${test_section_id} $0
  2040. FunctionEnd
  2041. </pre>
  2042. <a name="ssectionsetsize"></a><h4>4.9.13.7 SectionSetSize</h4>
  2043. <pre>section_index new_size
  2044. </pre>
  2045. <p>Sets the size of the section specified by section_index. Note that the index starts with zero. The Value for Size must be entered in KiloByte and supports only whole numbers.</p>
  2046. <pre>Section test test_section_id
  2047. SectionEnd
  2048. Function .onInit
  2049. # set required size of section 'test' to 100 bytes
  2050. SectionSetSize ${test_section_id} 100
  2051. FunctionEnd
  2052. </pre>
  2053. <a name="ssectiongetsize"></a><h4>4.9.13.8 SectionGetSize</h4>
  2054. <pre>section_index user_var
  2055. </pre>
  2056. <p>Gets the size of the section specified by section_index and stores the value in the given user variable. Note that the index starts with zero. The error flag will be set if the section index is out of range.</p>
  2057. <pre>Section test test_section_id
  2058. SectionEnd
  2059. Function .onInit
  2060. # increase required size of section 'test' by 100 KiB
  2061. SectionGetSize ${test_section_id} $0
  2062. IntOp $0 $0 + 100
  2063. SectionSetSize ${test_section_id} $0
  2064. FunctionEnd
  2065. </pre>
  2066. <a name="ssetcurinsttype"></a><h4>4.9.13.9 SetCurInstType</h4>
  2067. <pre>inst_type_idx
  2068. </pre>
  2069. <p>Sets the current <a href="Chapter4.html#ainsttype">InstType</a>. inst_type_idx should be between 0 and 31. The error flag is <b>not</b> set if an out of range <a href="Chapter4.html#ainsttype">InstType</a> was used.</p>
  2070. <a name="sgetcurinsttype"></a><h4>4.9.13.10 GetCurInstType</h4>
  2071. <pre>user_var
  2072. </pre>
  2073. <p>Get the current <a href="Chapter4.html#ainsttype">InstType</a> and stores it in user_var. If the first install type is selected, 0 will be put in user_var. If the second install type is selected, 1 will be put in user_var, and so on. The value of ${NSIS_MAX_INST_TYPES} (32 by default) means that the user selected a custom set of sections (Simply selecting &quot;Custom&quot; in the drop-down menu is not enough to trigger this, the value is calculated by the sections actually selected).</p>
  2074. <a name="sinsttypesettext"></a><h4>4.9.13.11 InstTypeSetText</h4>
  2075. <pre>inst_type_idx text
  2076. </pre>
  2077. <p>Sets the text of the specified <a href="Chapter4.html#ainsttype">InstType</a>. If the text is empty then the <a href="Chapter4.html#ainsttype">InstType</a> is removed. By using a previously unused inst_type_idx number you can create new InstTypes. To add/remove Sections to this new <a href="Chapter4.html#ainsttype">InstType</a> see <a href="Chapter4.html#sectionsetinsttypes">SectionSetInstTypes</a>. Unlike <a href="Chapter4.html#ssectionin">SectionIn</a> the index is zero based, which means the first install type's index is 0.</p>
  2078. <pre>InstType a
  2079. InstType b
  2080. Function .onInit
  2081. # set first installation type's name to $WINDIR
  2082. InstTypeSetText 0 $WINDIR
  2083. # set second installation type's name to $TEMP
  2084. InstTypeSetText 1 $TEMP
  2085. FunctionEnd
  2086. </pre>
  2087. <a name="sinsttypegettext"></a><h4>4.9.13.12 InstTypeGetText</h4>
  2088. <pre>inst_type_idx user_var
  2089. </pre>
  2090. <p>Gets the text of the specified <a href="Chapter4.html#ainsttype">InstType</a>.</p>
  2091. <pre>InstType a
  2092. InstType b
  2093. Function .onInit
  2094. InstTypeGetText 0 $0
  2095. DetailPrint $0 # prints 'a'
  2096. InstTypeGetText 1 $0
  2097. DetailPrint $0 # prints 'b'
  2098. FunctionEnd
  2099. </pre>
  2100. <a name="ui"></a><h3>4.9.14 User Interface Instructions</h3>
  2101. <a name="BringToFront"></a><h4>4.9.14.1 BringToFront</h4>
  2102. <p>Makes the installer window visible and brings it to the top of the window list. If an application was executed that shows itself in front of the installer, <a href="Chapter4.html#BringToFront">BringToFront</a> would bring the installer back in focus.</p>
  2103. <p>Recent Windows versions restrict the setting of foreground windows. If the user is working with another application during installation, the user may be notified using a different method.</p>
  2104. <a name="createfont"></a><h4>4.9.14.2 CreateFont</h4>
  2105. <pre>user_var(handle output) face_name [height] [weight] [/ITALIC] [/UNDERLINE] [/STRIKE]
  2106. </pre>
  2107. <p>Creates a font and puts its handle into user_var. For more information about the different parameters have a look at <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_8fp0.asp">MSDN's page about the Win32 API function CreateFont()</a>.</p>
  2108. <p>You can get the current font used by NSIS using the ^Font and ^FontSize <a href="Chapter4.html#langstring">LangString</a>s.</p>
  2109. <pre>!include WinMessages.nsh
  2110. GetDlgItem $0 $HWNDPARENT 1
  2111. CreateFont $1 &quot;Times New Roman&quot; &quot;7&quot; &quot;700&quot; /UNDERLINE
  2112. SendMessage $0 ${WM_SETFONT} $1 1
  2113. </pre>
  2114. <a name="detailprint"></a><h4>4.9.14.3 DetailPrint</h4>
  2115. <pre>user_message
  2116. </pre>
  2117. <p>Adds the string &quot;user_message&quot; to the details view of the installer.</p>
  2118. <pre>DetailPrint &quot;this message will be shown in the installation window&quot;
  2119. </pre>
  2120. <a name="enablewindow"></a><h4>4.9.14.4 EnableWindow</h4>
  2121. <pre>hwnd state(1|0)
  2122. </pre>
  2123. <p>Enables or disables mouse and keyboard input to the specified window or control. Possible states are 0 (disabled) or 1 (enabled).</p>
  2124. <pre>GetDlgItem $0 $HWNDPARENT 1
  2125. EnableWindow $0 0
  2126. Sleep 1000
  2127. EnableWindow $0 1
  2128. </pre>
  2129. <a name="findwindow"></a><h4>4.9.14.5 FindWindow</h4>
  2130. <pre>user_var(hwnd output) windowclass [windowtitle] [windowparent] [childafter]
  2131. </pre>
  2132. <p>Searches for a window. Behaves like Win32's FindWindowEx(). Searches by windowclass (and/or windowtitle if specified). If windowparent or childafter are specified, the search will be restricted as such. If windowclass or windowtitle is specified as &quot;&quot;, they will not be used for the search. If the window is not found the user variable is set to 0. To accomplish old-style <a href="Chapter4.html#findwindow">FindWindow</a> behavior, use <a href="Chapter4.html#findwindow">FindWindow</a> with <a href="Chapter4.html#sendmessage">SendMessage</a>.</p>
  2133. <pre>FindWindow $1 &quot;#32770&quot; &quot;&quot; $HWNDPARENT # Finds the inner dialog
  2134. FindWindow $2 &quot;EDIT&quot; &quot;&quot; $1 # Finds the first edit control in the inner dialog
  2135. </pre>
  2136. <a name="getdlgitem"></a><h4>4.9.14.6 GetDlgItem</h4>
  2137. <pre>user_var(output) dialog item_id
  2138. </pre>
  2139. <p>Retrieves the handle of a control identified by item_id in the specified dialog box dialog. If you want to get the handle of a control in the inner dialog, first use FindWindow to get the handle of the inner dialog.</p>
  2140. <pre>GetDlgItem $0 $HWNDPARENT 1 # next/install button
  2141. </pre>
  2142. <a name="hidewindow"></a><h4>4.9.14.7 HideWindow</h4>
  2143. <p>Hides the installer window.</p>
  2144. <a name="iswindow"></a><h4>4.9.14.8 IsWindow</h4>
  2145. <pre>HWND jump_if_window [jump_if_not_window]
  2146. </pre>
  2147. <p>If HWND is a window, Gotos jump_if_window, otherwise, Gotos jump_if_not_window (if specified).</p>
  2148. <pre>GetDlgItem $0 $HWNDPARENT 1
  2149. IsWindow $0 0 +3
  2150. MessageBox MB_OK &quot;found a window&quot;
  2151. Goto +2
  2152. MessageBox MB_OK &quot;no window&quot;
  2153. </pre>
  2154. <a name="lockwindow"></a><h4>4.9.14.9 LockWindow</h4>
  2155. <pre>on|off
  2156. </pre>
  2157. <p><em>LockWindow on</em> prevents the main window from redrawing itself upon changes. When <em>LockWindow off</em> is used, all controls that weren't redrawn since <em>LockWindow on</em> will be redrawn. This makes the pages flickering look nicer because now it flickers a group of controls at the same time, instead of one control at a time. The individual control flickering is more noticeable on old computers.</p>
  2158. <a name="sendmessage"></a><h4>4.9.14.10 SendMessage</h4>
  2159. <pre>HWND msg wparam lparam [user_var(return value)] [/TIMEOUT=time_in_ms]
  2160. </pre>
  2161. <p>Sends a message to HWND. If a user variable $x is specified as the last parameter (or one before the last if you use /TIMEOUT), the return value from SendMessage will be stored in it. Note that when specifying 'msg' you must just use the integer value of the message. Include WinMessages.nsh to have all Windows messages defined in your script. If you wish to send strings use &quot;STR:a string&quot; as wParam or lParam where needed. Use /TIMEOUT=time_in_ms to specify the duration, in milliseconds, of the time-out period.</p>
  2162. <pre>!include WinMessages.nsh
  2163. FindWindow $0 &quot;Winamp v1.x&quot;
  2164. SendMessage $0 ${WM_CLOSE} 0 0
  2165. GetDlgItem $1 $HWNDPARENT 2
  2166. SendMessage $1 ${WM_SETTEXT} 0 &quot;STR:Goodbye&quot;
  2167. </pre>
  2168. <a name="setautoclose"></a><h4>4.9.14.11 SetAutoClose</h4>
  2169. <pre>true|false
  2170. </pre>
  2171. <p>Overrides the default auto window-closing flag (specified for the installer using <a href="Chapter4.html#aautoclosewindow">AutoCloseWindow</a>, and false for the uninstaller). Specify 'true' to have the install window immediately disappear after the install has completed, or 'false' to make it require a manual close.</p>
  2172. <a name="setbrandingimage"></a><h4>4.9.14.12 SetBrandingImage</h4>
  2173. <pre>[/IMGID=item_id_in_dialog] [/RESIZETOFIT] path_to_bitmap_file.bmp
  2174. </pre>
  2175. <p>Sets the current bitmap file displayed as the branding image. If no IMGID is specified, the first image control found will be used, or the image control created by <a href="Chapter4.html#aaddbrandingimage">AddBrandingImage</a>. Note that this bitmap must be present on the user's machine. Use File first to put it there. If /RESIZETOFIT is specified the image will be automatically resized (very poorly) to the image control size. If you used <a href="Chapter4.html#aaddbrandingimage">AddBrandingImage</a> you can get this size by compiling your script and watching for <a href="Chapter4.html#aaddbrandingimage">AddBrandingImage</a> output, it will tell you the size. SetBrandingImage will not work when called from .onInit!</p>
  2176. <a name="setdetailsview"></a><h4>4.9.14.13 SetDetailsView</h4>
  2177. <pre>show|hide
  2178. </pre>
  2179. <p>Shows or hides the details, depending on which parameter you pass. Overrides the default details view, which is set via <a href="Chapter4.html#ashowinstdetails">ShowInstDetails</a>.</p>
  2180. <a name="setdetailsprint"></a><h4>4.9.14.14 SetDetailsPrint</h4>
  2181. <pre>none|listonly|textonly|both|lastused
  2182. </pre>
  2183. <p>Sets mode at which commands print their status. None has commands be quiet, listonly has status text only added to the listbox, textonly has status text only printed to the status bar, and both enables both (the default). For extracting many small files, textonly is recommended (especially on win9x with smooth scrolling enabled).</p>
  2184. <pre>SetDetailsPrint none
  2185. File &quot;secret file.dat&quot;
  2186. SetDetailsPrint both
  2187. </pre>
  2188. <a name="setctlcolors"></a><h4>4.9.14.15 SetCtlColors</h4>
  2189. <pre>hwnd [/BRANDING] [text_color|SYSCLR:text_color_id] [transparent|bg_color|SYSCLR:bg_color_id]
  2190. </pre>
  2191. <p>Sets the text and background color of a static control, edit control, button or a dialog. <em>text_color</em> and <em>bg_color</em> don't accept variables. Use <a href="Chapter4.html#getdlgitem">GetDlgItem</a> to get the handle (HWND) of the control. To make the control transparent specify <code>transparent</code> as the background color value. Prefix the color value with <code>SYSCLR:</code> to specify a Windows <code>COLOR_*</code> constant. You can also specify <code>/BRANDING</code> with or without text color and background color to make the control completely gray (or any other color you choose). This is used by the branding text control in the MUI.</p>
  2192. <pre>Page Components &quot;&quot; CmpntPageShow
  2193. Function CmpntPageShow
  2194. FindWindow $1 &quot;#32770&quot; &quot;&quot; $HWNDPARENT
  2195. GetDlgItem $0 $1 1006
  2196. SetCtlColors $0 0xFF0000 0x00FF00 ; Red on Green
  2197. GetDlgItem $0 $1 1022
  2198. SetCtlColors $0 SYSCLR:23 SYSCLR:24 ; COLOR_INFOTEXT on COLOR_INFOBK
  2199. FunctionEnd
  2200. </pre>
  2201. <p><div class="wb"> <b>Warning:</b> Setting the background color of check boxes to <code>transparent</code> may not function properly when using <a href="Chapter4.html#axpstyle"><code>XPStyle</code></a><code> on</code>. The background may be completely black instead of transparent when using certain Windows themes. </div></p>
  2202. <a name="setsilent"></a><h4>4.9.14.16 SetSilent</h4>
  2203. <pre>silent | normal
  2204. </pre>
  2205. <p>Sets the installer to silent mode or normal mode. See <a href="Chapter4.html#asilentinstall">SilentInstall</a> for more information about silent installations. Can only be used in <a href="Chapter4.html#oninit">.onInit</a>.</p>
  2206. <a name="showwindow"></a><h4>4.9.14.17 ShowWindow</h4>
  2207. <pre>hwnd show_state
  2208. </pre>
  2209. <p>Sets the visibility of a window. Possible show_states are the same as the Windows <a href="http://msdn2.microsoft.com/en-us/library/ms633548">ShowWindow</a> function. SW_* constants are defined in <a href="../Include/WinMessages.nsh">Include\WinMessages.nsh</a>.</p>
  2210. <pre>!include WinMessages.nsh
  2211. GetDlgItem $0 $HWNDPARENT 1
  2212. ShowWindow $0 ${SW_HIDE}
  2213. Sleep 1000
  2214. ShowWindow $0 ${SW_SHOW}
  2215. </pre>
  2216. <a name="langsinstructions"></a><h3>4.9.15 Multiple Languages Instructions</h3>
  2217. <a name="loadlanguagefile"></a><h4>4.9.15.1 LoadLanguageFile</h4>
  2218. <pre>language_file.nlf
  2219. </pre>
  2220. <p>Loads a language file for the construction of a language table. All of the language files that ship with NSIS are in <a href="../Contrib/Language files">Contrib\Language Files</a></p>
  2221. <p>After you have inserted the language file ${LANG_langfile} will be defined as the language id (for example, ${LANG_ENGLISH} will be defined as 1033). Use it with <a href="Chapter4.html#langstring">LangString</a>, <a href="Chapter4.html#licenselangstring">LicenseLangString</a>, <a href="Chapter4.html#langdll">LangDLL</a> and <a href="Chapter4.html#viaddversionkey">VIAddVersionKey</a>.</p>
  2222. <a name="langstring"></a><h4>4.9.15.2 LangString</h4>
  2223. <pre>name language_id|0 string
  2224. </pre>
  2225. <p>Defines a multilingual string. This means its value may be different (or not, it's up to you) for every language. It allows you to easily make your installer multilingual without the need to add massive switches to the script.</p>
  2226. <p>Each language string has a name that identifies it and a value for each language used by the installer. They can be used in any runtime string in the script. To use a language string all you need to add to the string is $(LangString_name_here) where you want the <a href="Chapter4.html#langstring">LangString</a> to be inserted.</p>
  2227. <p><b>Notes:</b></p>
  2228. <ul>
  2229. <li>Unlike defines that use curly braces - {}, language strings use parenthesis - ().</li><li>If you change the language in the .onInit function, note that language strings in .onInit will still use the detected language based on the user's default Windows language because the language is initialized after .onInit.</li><li>Always set language strings for every language in your script.</li><li>If you set the language ID to 0 the last used language by <a href="Chapter4.html#langstring">LangString</a> or <a href="Chapter4.html#loadlanguagefile">LoadLanguageFile</a> will be used.</li></ul>
  2230. <p><b>Example of usage:</b></p>
  2231. <pre> LangString message ${LANG_ENGLISH} &quot;English message&quot;
  2232. LangString message ${LANG_FRENCH} &quot;French message&quot;
  2233. LangString message ${LANG_KOREAN} &quot;Korean message&quot;
  2234. MessageBox MB_OK &quot;A translated message: $(message)&quot;
  2235. </pre>
  2236. <a name="licenselangstring"></a><h4>4.9.15.3 LicenseLangString</h4>
  2237. <pre>name language_id|0 license_path
  2238. </pre>
  2239. <p>Does the same as <a href="Chapter4.html#langstring">LangString</a> only it loads the string from a text/RTF file and defines a special LangString that can only be used by <a href="Chapter4.html#alicensedata">LicenseData</a>.</p>
  2240. <pre>LicenseLangString license ${LANG_ENGLISH} license-english.txt
  2241. LicenseLangString license ${LANG_FRENCH} license-french.txt
  2242. LicenseLangString license ${LANG_GERMAN} license-german.txt
  2243. LicenseData $(license)
  2244. </pre>
  2245. <a name="langs"></a><h2>4.10 Multiple Languages</h2>
  2246. <p>As of version 2 NSIS fully supports multiple languages. The interface of one installer can support multiple languages.</p>
  2247. <p>Use <a href="Chapter4.html#loadlanguagefile">LoadLanguageFile</a> for every language to load the default interface texts and language properties. Visit the <a href="http://forums.winamp.com/showthread.php?t=157119">NSIS translations forum</a> for more information about creating new language files.</p>
  2248. <p>The default interface texts can easily be changed using instructions like <a href="Chapter4.html#acomponenttext">ComponentText</a> etc.</p>
  2249. <p>You can also use the contents of the standard language strings in your own strings (for example, $(^Name) contains the installer's name set using the <a href="Chapter4.html#aname">Name</a> instruction). The names of all standard language strings are listed as comments just above the strings in the language files. The language files are located in <a href="../Contrib/Language files">Contrib\Language Files</a>.</p>
  2250. <p>To create your own language strings, use <a href="Chapter4.html#langstring">LangString</a>.</p>
  2251. <p>For an example of an installer with multiple languages, see <a href="../Examples/languages.nsi">languages.nsi</a>.</p>
  2252. <a name="langselection"></a><h3>4.10.1 Language Selection</h3>
  2253. <p>When the installer starts up it goes through these steps to select the interface language:</p>
  2254. <ol>
  2255. <li>Get user's default Windows UI language</li><li>Find a perfect match for the language</li><li>If there is no perfect match, find a primary language match</li><li>If there is no match, use the first language defined in the script (make sure your first language is a common one like English)</li><li>If the language variable <a href="Chapter4.html#varconstant">$LANGUAGE</a> has changed during .onInit, NSIS goes through steps 2 to 4 again.</li></ol>
  2256. <a name="langdll"></a><h3>4.10.2 LangDLL Plug-in</h3>
  2257. <p>The LangDLL plug-in allows you to give the user an option to choose the language of the installer. Just push the language id (${LANG_langfile}) and its name for every language in your installer, then the number of languages pushed, the caption, and the text that tells the user to select the language, call the plug-in function named LangDialog, pop the returned value into $LANGUAGE and you're good to go. If the user clicks on the cancel button the return value will be &quot;cancel&quot;.</p>
  2258. <p>For an example of usage see <a href="../Examples/languages.nsi">languages.nsi</a>.</p>
  2259. <a name="rtl"></a><h3>4.10.3 RTL Languages</h3>
  2260. <p>RTL languages are languages that are written from right to left (e.g. Arabic and Hebrew). NSIS fully supports RTL languages. In the language file there is a place to specify if the language is RTL or not. To find out at runtime if the current language is RTL or not, check the value of the $(^RTL) language string. It will be 1 if the language is RTL and 0 otherwise. This can be useful when using plug-ins that create dialogs, they usually have RTL settings too.</p>
  2261. <a name="plugindlls"></a><h2>4.11 Plug-in DLLs</h2>
  2262. <p>The abilities of the NSIS scripting language can be extended by utilising functionality provided in a DLL file. Probably the best known example of this is the InstallOptions.dll bundled with every NSIS release.</p>
  2263. <p>When the NSIS compiler starts it scans the plug-ins directory for DLLs and makes a list of the plug-ins found and their exported functions. During compilation, if a sequence such as fred::flintstone is encountered where the compiler expected to find a language keyword the compiler will look through this list. If a list entry specifies that fred.dll exports function flintstone NSIS will pack the fred.dll file into the created installer binary.</p>
  2264. <p>During execution of a plug-in command NSIS will unpack the necessary DLL to a temporary folder ($PLUGINSDIR), push all of the arguments specified (right-to-left order), and then execute the DLL function.</p>
  2265. <a name="usingplug"></a><h3>4.11.1 Using Plug-in Commands</h3>
  2266. <p>A plug-in call looks like this:</p>
  2267. <pre>InstallOptions::dialog &quot;ini_file_location.ini&quot;
  2268. </pre>
  2269. <p>All parameters are pushed onto the stack (in this case, the plug-in function only needs one parameter). Some plug-in commands may not need any parameters on the stack, others might require more of them. To use a plug-in command you will need to read the documentation for the plug-in so that you know what parameters its functions require.</p>
  2270. <a name="calldiskplug"></a><h3>4.11.2 Calling plug-ins manually</h3>
  2271. <p>If you want to call a plug-in that is stored on user's hard drive or somewhere else, use <a href="Chapter4.html#callinstdll">CallInstDLL</a>. Almost all plug-ins provide installer functionality, so using plug-in commands is way easier. Using <a href="Chapter4.html#callinstdll">CallInstDLL</a> can be useful when you have created plug-ins that are linked to a certain version of your application and are being copied to the installation folder.</p>
  2272. <a name="silent"></a><h2>4.12 Silent Installers/Uninstallers</h2>
  2273. <p>Silent installers are installers which require no user intervention and have no user interface. The user doesn't see any dialog and isn't asked any questions. This is useful for network administrators who wish to install or uninstall something without user intervention so they can perform the operation quickly over any number of computers. It is also useful for other developers who wish to embed another installer in their own and collect all of the required information on their installer instead of showing two installers.</p>
  2274. <p>NSIS installers and uninstallers can be both silent and not silent. When an installer or an uninstaller is silent, not all callback functions are called. <a href="Chapter4.html#onguiinit">.onGUIInit</a>, <a href="Chapter4.html#onguiend">.onGUIEnd</a>, their uninstaller equivalents and any callback related to a specific page or page type will not be called.</p>
  2275. <p>There are several methods to make an installer or an uninstaller silent:</p>
  2276. <ol>
  2277. <li><a href="Chapter4.html#asilentinstall">SilentInstall</a> and <a href="Chapter4.html#asilentuninstall">SilentUninstall</a></li><li><a href="Chapter4.html#setsilent">SetSilent</a></li><li>Passing /S on the command line (case sensitive)</li></ol>
  2278. <p>To check if the installer/uninstaller is silent use <a href="Chapter4.html#ifsilent">IfSilent</a>.</p>
  2279. <p>To make sure your installer will be silent when it needs to, you should check with <a href="Chapter4.html#ifsilent">IfSilent</a> before each command that might require user intervention or create a window. The <a href="Chapter4.html#messagebox">MessageBox</a> command, which is the most common culprit in silent installers, has the /SD switch to set a default answer for silent installers. If you want your installer/uninstaller to be able to be completely silent you should use this switch. All internal NSIS message boxes have defaults for silent installers. The <a href="../Examples/silent.nsi">silent.nsi example</a> demonstrates all aspects of this topic.</p>
  2280. <p>Since the directory page is not shown in silent installers the user has an option to specify the installation directory on the command line (this also works on non-silent installers/uninstallers). To do that, the user uses the /D switch as in the following example:</p>
  2281. <pre>foo.exe /S /D=C:\Program Files\Foo
  2282. </pre>
  2283. <p>If your installer/uninstaller requires some more information that can not be gathered when silent, you can allow the user to specify that information on the command line and process it in .onInit. You can use <a href="AppendixE.html#getoptions">GetOptions</a>.</p>
  2284. <pre>!include FileFunc.nsh
  2285. !insertmacro GetParameters
  2286. !insertmacro GetOptions
  2287. Function .onInit
  2288. ${GetParameters} $R0
  2289. ClearErrors
  2290. ${GetOptions} $R0 /USERNAME= $0
  2291. FunctionEnd
  2292. </pre>
  2293. <p>The above example will copy the value the user passes on after /USERNAME= into $0. This allows the user to specify the required information on the command line instead of using the interactive user interface. The user can use:</p>
  2294. <pre>foo.exe /S /USERNAME=Bar /D=C:\Program Files\Foo
  2295. </pre>
  2296. <p>or:</p>
  2297. <pre>foo.exe /S /USERNAME=string with spaces /D=C:\Program Files\Foo
  2298. </pre>
  2299. <p>or:</p>
  2300. <pre>foo.exe /S /USERNAME=&quot;string with spaces&quot; /D=C:\Program Files\Foo
  2301. </pre>
  2302. <p>If your installer/uninstaller requires a lot of information and you want it to be able to be silent, you should allow the user to pass on a path to an answers file. This would be much more comfortable than writing all of the information on the command line.</p>
  2303. <p><a href='Chapter3.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='Chapter5.html'>Next</a></p>
  2304. <hr />
  2305. <address>
  2306. </address>
  2307. </body>
  2308. </html>