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