AppendixC.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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>Useful Scripts</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='AppendixB.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixD.html'>Next</a></p>
  11. <ul>
  12. <li><a class="btitle" href="AppendixC.html#usefulfunctions"><b>Appendix C: </b>Useful Scripts</a></li>
  13. <ul>
  14. <li><a href="AppendixC.html#getieversion">Get Internet Explorer version</a></li>
  15. <li><a href="AppendixC.html#detect.netframework">Is .NET Framework installed?</a></li>
  16. <li><a href="AppendixC.html#isflashinstalled">Is Macromedia Flash Player installed?</a></li>
  17. <li><a href="AppendixC.html#connectinternet">Connect to the Internet</a></li>
  18. <li><a href="AppendixC.html#installerfilename">Get Installer Filename</a></li>
  19. <li><a href="AppendixC.html#multipleinstances">Prevent Multiple Instances</a></li>
  20. <li><a href="AppendixC.html#morefuncs">More</a></li>
  21. </ul>
  22. </ul>
  23. <a name="usefulfunctions"></a><h1>Appendix C: Useful Scripts</h1>
  24. <a name="getieversion"></a><h2>C.1 Get Internet Explorer version</h2>
  25. <pre> ; GetIEVersion
  26. ;
  27. ; Based on Yazno's function, http://yazno.tripod.com/powerpimpit/
  28. ; Returns 1-6 (IE Version) or '' (IE is not installed) on top of the stack
  29. ;
  30. ; Usage:
  31. ; Call GetIEVersion
  32. ; Pop $R0 ; at this point $R0 is &quot;5&quot; or whatnot
  33. Function GetIEVersion
  34. Push $R0
  35. ClearErrors
  36. ReadRegStr $R0 HKLM &quot;Software\Microsoft\Internet Explorer&quot; &quot;Version&quot;
  37. IfErrors lbl_123 lbl_456
  38. lbl_456: ; ie 4+
  39. Strcpy $R0 $R0 1
  40. Goto lbl_done
  41. lbl_123: ; older ie version
  42. ClearErrors
  43. ReadRegStr $R0 HKLM &quot;Software\Microsoft\Internet Explorer&quot; &quot;IVer&quot;
  44. IfErrors lbl_error
  45. StrCpy $R0 $R0 3
  46. StrCmp $R0 '100' lbl_ie1
  47. StrCmp $R0 '101' lbl_ie2
  48. StrCmp $R0 '102' lbl_ie2
  49. StrCpy $R0 '3' ; default to ie3 if not 100, 101, or 102.
  50. Goto lbl_done
  51. lbl_ie1:
  52. StrCpy $R0 '1'
  53. Goto lbl_done
  54. lbl_ie2:
  55. StrCpy $R0 '2'
  56. Goto lbl_done
  57. lbl_error:
  58. StrCpy $R0 ''
  59. lbl_done:
  60. Exch $R0
  61. FunctionEnd
  62. </pre>
  63. <a name="detect.netframework"></a><h2>C.2 Is .NET Framework installed?</h2>
  64. <pre> ; IsDotNETInstalled
  65. ;
  66. ; Based on GetDotNETVersion
  67. ; http://nsis.sourceforge.net/Get_.NET_Version
  68. ;
  69. ; Usage:
  70. ; Call IsDotNETInstalled
  71. ; Pop $0
  72. ; StrCmp $0 1 found_dotNETFramework no_dotNETFramework
  73. Function IsDotNETInstalled
  74. Push $0
  75. Push $1
  76. StrCpy $0 1
  77. System::Call &quot;mscoree::GetCORVersion(w, i ${NSIS_MAX_STRLEN}, *i) i .r1&quot;
  78. StrCmp $1 0 +2
  79. StrCpy $0 0
  80. Pop $1
  81. Exch $0
  82. FunctionEnd
  83. </pre>
  84. <a name="isflashinstalled"></a><h2>C.3 Is Macromedia Flash Player installed?</h2>
  85. <pre> ; IsFlashInstalled
  86. ;
  87. ; By Yazno, http://yazno.tripod.com/powerpimpit/
  88. ; Returns the result on top of the stack
  89. ;
  90. ; Usage:
  91. ; Call IsFlashInstalled
  92. ; Pop $R0 ; $R0 is &quot;1&quot; or &quot;0&quot; at this point
  93. Function IsFlashInstalled
  94. Push $R0
  95. ClearErrors
  96. ReadRegStr $R0 HKCR &quot;CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}&quot; &quot;&quot;
  97. IfErrors lbl_na
  98. StrCpy $R0 1
  99. Goto lbl_end
  100. lbl_na:
  101. StrCpy $R0 0
  102. lbl_end:
  103. Exch $R0
  104. FunctionEnd
  105. </pre>
  106. <a name="connectinternet"></a><h2>C.4 Connect to the Internet</h2>
  107. <pre> ; ConnectInternet (uses Dialer plug-in)
  108. ; Written by Joost Verburg
  109. ;
  110. ; This function attempts to make a connection to the internet if there is no
  111. ; connection available. If you are not sure that a system using the installer
  112. ; has an active internet connection, call this function before downloading
  113. ; files with NSISdl.
  114. ;
  115. ; The function requires Internet Explorer 3, but asks to connect manually if
  116. ; IE3 is not installed.
  117. Function ConnectInternet
  118. Push $R0
  119. ClearErrors
  120. Dialer::AttemptConnect
  121. IfErrors noie3
  122. Pop $R0
  123. StrCmp $R0 &quot;online&quot; connected
  124. MessageBox MB_OK|MB_ICONSTOP &quot;Cannot connect to the internet.&quot;
  125. Quit ;This will quit the installer. You might want to add your own error handling.
  126. noie3:
  127. ; IE3 not installed
  128. MessageBox MB_OK|MB_ICONINFORMATION &quot;Please connect to the internet now.&quot;
  129. connected:
  130. Pop $R0
  131. FunctionEnd
  132. </pre>
  133. <a name="installerfilename"></a><h2>C.5 Get Installer Filename</h2>
  134. <pre> System::Call 'kernel32::GetModuleFileName(p 0, t .R0, i ${NSIS_MAX_STRLEN}) i.r1'
  135. ;$R0 will contain the installer filename
  136. </pre>
  137. <a name="multipleinstances"></a><h2>C.6 Prevent Multiple Instances</h2>
  138. <p>Put the following code in your <a href="Chapter4.html#oninit">.onInit function</a>:</p>
  139. <pre> System::Call 'kernel32::CreateMutex(p 0, i 0, t &quot;myMutex&quot;) p .r1 ?e'
  140. Pop $R0
  141. StrCmp $R0 0 +3
  142. MessageBox MB_OK|MB_ICONEXCLAMATION &quot;The installer is already running.&quot;
  143. Abort
  144. </pre>
  145. <p>'myMutex' must be replaced by a unique value!</p>
  146. <a name="morefuncs"></a><h2>C.7 More</h2>
  147. <p>You can find more useful scripts on <a href="http://nsis.sourceforge.net/wiki/">the NSIS Wiki</a>, <a href="http://forums.winamp.com/forumdisplay.php?s=&forumid=65">the NSIS forum</a> and the <a href="http://nsis.sourceforge.net/">NSIS development page</a>.</p>
  148. <p><a href='AppendixB.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixD.html'>Next</a></p>
  149. <hr />
  150. <address>
  151. </address>
  152. </body>
  153. </html>