123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Useful Scripts</title>
- <meta name="viewport" content="width=device-width, initial-scale=1" /><meta name="generator" content="Halibut v1.0 (NSIS Custom Build, SVN:r7318) xhtml-backend" />
- <link rel="stylesheet" href="style.css" type='text/css' />
- </head>
- <body>
- <p><a href='AppendixB.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixD.html'>Next</a></p>
- <ul>
- <li><a class="btitle" href="AppendixC.html#usefulfunctions"><b>Appendix C: </b>Useful Scripts</a></li>
- <ul>
- <li><a href="AppendixC.html#getieversion">Get Internet Explorer version</a></li>
- <li><a href="AppendixC.html#detect.netframework">Is .NET Framework installed?</a></li>
- <li><a href="AppendixC.html#isflashinstalled">Is Macromedia Flash Player installed?</a></li>
- <li><a href="AppendixC.html#connectinternet">Connect to the Internet</a></li>
- <li><a href="AppendixC.html#multipleinstances">Prevent Multiple Instances</a></li>
- <li><a href="AppendixC.html#morefuncs">More</a></li>
- </ul>
- </ul>
- <a name="usefulfunctions"></a><h1>Appendix C: Useful Scripts</h1>
- <a name="getieversion"></a><h2>C.1 Get Internet Explorer version</h2>
- <pre>; GetIEVersion
- ;
- ; Returns 1-11 (IE Version) or '' (IE is not installed) on top of the stack
- ;
- ; Usage:
- ; Call GetIEVersion
- ; Pop $R0 ; $R0 is "5" etc.
- Function GetIEVersion
- Push $R0
- ReadRegStr $R0 HKLM "Software\Microsoft\Internet Explorer" "svcVersion" ; IE v10+
- StrCpy $R0 $R0 2
- IntCmp $R0 9 "" "" lbl_done
- ClearErrors
- ReadRegStr $R0 HKLM "Software\Microsoft\Internet Explorer" "Version" ; IE v4..9
- IfErrors lbl_123
- StrCpy $R0 $R0 1 ; Note: This truncates 5.50 to 5 etc.
- Goto lbl_done
- lbl_123:
- !if "${NSIS_PTR_SIZE}" > 4
- StrCpy $R0 ""
- !else
- ReadRegStr $R0 HKLM "Software\Microsoft\Internet Explorer" "IVer" ; IE v1..3
- IntCmp $R0 99 "" "" +3
- StrCpy $R0 ""
- Goto lbl_done
- IntOp $R0 $R0 & 3 ; 100..103->0..3
- IntCmp $R0 2 +2 "" +2
- IntOp $R0 $R0 + 1 ; Bump 100->v1 and 101->v2 (Is 101 v1.5 or 2.0?)
- !endif
- lbl_done:
- Exch $R0
- FunctionEnd
- </pre>
- <a name="detect.netframework"></a><h2>C.2 Is .NET Framework installed?</h2>
- <pre>; IsDotNETInstalled
- ;
- ; NOTE: This is only able to detect .NET v1.x and v2.x!
- ;
- ; Based on GetDotNETVersion
- ; https://nsis.sourceforge.io/Get_.NET_Version
- ;
- ; Usage:
- ; Call IsDotNETInstalled
- ; Pop $0 ; 0 or 1
- ; StrCmp $0 1 found_dotNETFramework_v1_or_v2 no_dotNETFramework
- Function IsDotNETInstalled
- Push $0
- System::Call '"$SysDir\MSCOREE.dll"::GetCORVersion(w,i${NSIS_MAX_STRLEN},*i)i.r0?u'
- IntOp $0 $0 ! ; HRESULT (S_OK) -> BOOL
- Exch $0
- FunctionEnd
- </pre>
- <a name="isflashinstalled"></a><h2>C.3 Is Macromedia Flash Player installed?</h2>
- <pre>; IsFlashInstalled
- ;
- ; Usage:
- ; Call IsFlashInstalled
- ; Pop $R0 ; 1 or ""
- Function IsFlashInstalled
- Push $R0
- ReadRegStr $R0 HKCR "CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}" ""
- StrCmp $R0 "" +2
- StrCpy $R0 "1"
- Exch $R0
- FunctionEnd
- </pre>
- <a name="connectinternet"></a><h2>C.4 Connect to the Internet</h2>
- <pre> ; ConnectInternet (uses Dialer plug-in) - Written by Joost Verburg
- ;
- ; This function attempts to make a connection to the internet if there is no
- ; connection available. If you are not sure that a system using the installer
- ; has an active internet connection, call this function before downloading
- ; files with NSISdl.
- ;
- ; The function requires Internet Explorer 3, but asks to connect manually if
- ; IE3 is not installed.
-
- Function ConnectInternet
-
- Push $R0
-
- ClearErrors
- Dialer::AttemptConnect
- IfErrors noie3
-
- Pop $R0
- StrCmp $R0 "online" connected
- MessageBox MB_OK|MB_ICONSTOP "Cannot connect to the internet."
- Quit ; This will quit the installer. You might want to add your own error handling.
-
- noie3:
-
- ; IE3 not installed
- MessageBox MB_OK|MB_ICONINFORMATION "Please connect to the internet now."
-
- connected:
-
- Pop $R0
-
- FunctionEnd
- </pre>
- <a name="multipleinstances"></a><h2>C.5 Prevent Multiple Instances</h2>
- <p>Put the following code in your <a href="Chapter4.html#oninit">.onInit function</a>:</p>
- <pre> System::Call 'kernel32::CreateMutex(p 0, i 0, t "myMutex") p .r1 ?e'
- Pop $R0
-
- StrCmp $R0 0 +3
- MessageBox MB_OK|MB_ICONEXCLAMATION "The installer is already running."
- Abort
- </pre>
- <p>'myMutex' <em>must</em> be replaced by a unique string or GUID!</p>
- <a name="morefuncs"></a><h2>C.6 More</h2>
- <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>
- <p><a href='AppendixB.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixD.html'>Next</a></p>
- </body></html>
|