AppendixC.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Useful Scripts</title>
  4. <meta name="viewport" content="width=device-width, initial-scale=1" /><meta name="generator" content="Halibut v1.0 (NSIS Custom Build, SVN:r7318) xhtml-backend" />
  5. <link rel="stylesheet" href="style.css" type='text/css' />
  6. </head>
  7. <body>
  8. <p><a href='AppendixB.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixD.html'>Next</a></p>
  9. <ul>
  10. <li><a class="btitle" href="AppendixC.html#usefulfunctions"><b>Appendix C: </b>Useful Scripts</a></li>
  11. <ul>
  12. <li><a href="AppendixC.html#getieversion">Get Internet Explorer version</a></li>
  13. <li><a href="AppendixC.html#detect.netframework">Is .NET Framework installed?</a></li>
  14. <li><a href="AppendixC.html#isflashinstalled">Is Macromedia Flash Player installed?</a></li>
  15. <li><a href="AppendixC.html#connectinternet">Connect to the Internet</a></li>
  16. <li><a href="AppendixC.html#multipleinstances">Prevent Multiple Instances</a></li>
  17. <li><a href="AppendixC.html#morefuncs">More</a></li>
  18. </ul>
  19. </ul>
  20. <a name="usefulfunctions"></a><h1>Appendix C: Useful Scripts</h1>
  21. <a name="getieversion"></a><h2>C.1 Get Internet Explorer version</h2>
  22. <pre>; GetIEVersion
  23. ;
  24. ; Returns 1-11 (IE Version) or '' (IE is not installed) on top of the stack
  25. ;
  26. ; Usage:
  27. ; Call GetIEVersion
  28. ; Pop $R0 ; $R0 is &quot;5&quot; etc.
  29. Function GetIEVersion
  30. Push $R0
  31. ReadRegStr $R0 HKLM &quot;Software\Microsoft\Internet Explorer&quot; &quot;svcVersion&quot; ; IE v10+
  32. StrCpy $R0 $R0 2
  33. IntCmp $R0 9 &quot;&quot; &quot;&quot; lbl_done
  34. ClearErrors
  35. ReadRegStr $R0 HKLM &quot;Software\Microsoft\Internet Explorer&quot; &quot;Version&quot; ; IE v4..9
  36. IfErrors lbl_123
  37. StrCpy $R0 $R0 1 ; Note: This truncates 5.50 to 5 etc.
  38. Goto lbl_done
  39. lbl_123:
  40. !if &quot;${NSIS_PTR_SIZE}&quot; &gt; 4
  41. StrCpy $R0 &quot;&quot;
  42. !else
  43. ReadRegStr $R0 HKLM &quot;Software\Microsoft\Internet Explorer&quot; &quot;IVer&quot; ; IE v1..3
  44. IntCmp $R0 99 &quot;&quot; &quot;&quot; +3
  45. StrCpy $R0 &quot;&quot;
  46. Goto lbl_done
  47. IntOp $R0 $R0 &amp; 3 ; 100..103-&gt;0..3
  48. IntCmp $R0 2 +2 &quot;&quot; +2
  49. IntOp $R0 $R0 + 1 ; Bump 100-&gt;v1 and 101-&gt;v2 (Is 101 v1.5 or 2.0?)
  50. !endif
  51. lbl_done:
  52. Exch $R0
  53. FunctionEnd
  54. </pre>
  55. <a name="detect.netframework"></a><h2>C.2 Is .NET Framework installed?</h2>
  56. <pre>; IsDotNETInstalled
  57. ;
  58. ; NOTE: This is only able to detect .NET v1.x and v2.x!
  59. ;
  60. ; Based on GetDotNETVersion
  61. ; https://nsis.sourceforge.io/Get_.NET_Version
  62. ;
  63. ; Usage:
  64. ; Call IsDotNETInstalled
  65. ; Pop $0 ; 0 or 1
  66. ; StrCmp $0 1 found_dotNETFramework_v1_or_v2 no_dotNETFramework
  67. Function IsDotNETInstalled
  68. Push $0
  69. System::Call '&quot;$SysDir\MSCOREE.dll&quot;::GetCORVersion(w,i${NSIS_MAX_STRLEN},*i)i.r0?u'
  70. IntOp $0 $0 ! ; HRESULT (S_OK) -&gt; BOOL
  71. Exch $0
  72. FunctionEnd
  73. </pre>
  74. <a name="isflashinstalled"></a><h2>C.3 Is Macromedia Flash Player installed?</h2>
  75. <pre>; IsFlashInstalled
  76. ;
  77. ; Usage:
  78. ; Call IsFlashInstalled
  79. ; Pop $R0 ; 1 or &quot;&quot;
  80. Function IsFlashInstalled
  81. Push $R0
  82. ReadRegStr $R0 HKCR &quot;CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}&quot; &quot;&quot;
  83. StrCmp $R0 &quot;&quot; +2
  84. StrCpy $R0 &quot;1&quot;
  85. Exch $R0
  86. FunctionEnd
  87. </pre>
  88. <a name="connectinternet"></a><h2>C.4 Connect to the Internet</h2>
  89. <pre> ; ConnectInternet (uses Dialer plug-in) - Written by Joost Verburg
  90. ;
  91. ; This function attempts to make a connection to the internet if there is no
  92. ; connection available. If you are not sure that a system using the installer
  93. ; has an active internet connection, call this function before downloading
  94. ; files with NSISdl.
  95. ;
  96. ; The function requires Internet Explorer 3, but asks to connect manually if
  97. ; IE3 is not installed.
  98. Function ConnectInternet
  99. Push $R0
  100. ClearErrors
  101. Dialer::AttemptConnect
  102. IfErrors noie3
  103. Pop $R0
  104. StrCmp $R0 &quot;online&quot; connected
  105. MessageBox MB_OK|MB_ICONSTOP &quot;Cannot connect to the internet.&quot;
  106. Quit ; This will quit the installer. You might want to add your own error handling.
  107. noie3:
  108. ; IE3 not installed
  109. MessageBox MB_OK|MB_ICONINFORMATION &quot;Please connect to the internet now.&quot;
  110. connected:
  111. Pop $R0
  112. FunctionEnd
  113. </pre>
  114. <a name="multipleinstances"></a><h2>C.5 Prevent Multiple Instances</h2>
  115. <p>Put the following code in your <a href="Chapter4.html#oninit">.onInit function</a>:</p>
  116. <pre> System::Call 'kernel32::CreateMutex(p 0, i 0, t &quot;myMutex&quot;) p .r1 ?e'
  117. Pop $R0
  118. StrCmp $R0 0 +3
  119. MessageBox MB_OK|MB_ICONEXCLAMATION &quot;The installer is already running.&quot;
  120. Abort
  121. </pre>
  122. <p>'myMutex' <em>must</em> be replaced by a unique string or GUID!</p>
  123. <a name="morefuncs"></a><h2>C.6 More</h2>
  124. <p>You can find more useful scripts on <a href="https://nsis.sourceforge.io/wiki/">the NSIS Wiki</a>, <a href="http://forums.winamp.com/forumdisplay.php?s=&forumid=65">the NSIS forum</a> and the <a href="https://nsis.sourceforge.io/">NSIS development page</a>.</p>
  125. <p><a href='AppendixB.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixD.html'>Next</a></p>
  126. </body></html>