Previous | Contents | Next

Appendix C: Useful Scripts

C.1 Get Internet Explorer version

 ; GetIEVersion
 ; Based on Yazno's function,
 ; Returns 1-6 (IE Version) or '' (IE is not installed) on top of the stack
 ; Usage:
 ;   Call GetIEVersion
 ;   Pop $R0 ; at this point $R0 is "5" or whatnot

 Function GetIEVersion
 Push $R0
   ReadRegStr $R0 HKLM "Software\Microsoft\Internet Explorer" "Version"
   IfErrors lbl_123 lbl_456

   lbl_456: ; ie 4+
     Strcpy $R0 $R0 1
   Goto lbl_done

   lbl_123: ; older ie version
     ReadRegStr $R0 HKLM "Software\Microsoft\Internet Explorer" "IVer"
     IfErrors lbl_error

       StrCpy $R0 $R0 3
       StrCmp $R0 '100' lbl_ie1
       StrCmp $R0 '101' lbl_ie2
       StrCmp $R0 '102' lbl_ie2

       StrCpy $R0 '3' ; default to ie3 if not 100, 101, or 102.
       Goto lbl_done
           StrCpy $R0 '1'
         Goto lbl_done
           StrCpy $R0 '2'
         Goto lbl_done
       StrCpy $R0 ''
   Exch $R0

C.2 Is .NET Framework installed?

 ; IsDotNETInstalled
 ; Based on GetDotNETVersion
 ; Usage:
 ;   Call IsDotNETInstalled
 ;   Pop $0
 ;   StrCmp $0 1 found_dotNETFramework no_dotNETFramework

 Function IsDotNETInstalled
   Push $0
   Push $1

   StrCpy $0 1
   System::Call "mscoree::GetCORVersion(w, i ${NSIS_MAX_STRLEN}, *i) i .r1"
   StrCmp $1 0 +2
     StrCpy $0 0

   Pop $1
   Exch $0

C.3 Is Macromedia Flash Player installed?

 ; IsFlashInstalled
 ; By Yazno,
 ; Returns the result on top of the stack
 ; Usage:
 ;   Call IsFlashInstalled
 ;   Pop $R0 ; $R0 is "1" or "0" at this point 

 Function IsFlashInstalled
  Push $R0
  ReadRegStr $R0 HKCR "CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}" ""
  IfErrors lbl_na
    StrCpy $R0 1
  Goto lbl_end
    StrCpy $R0 0
  Exch $R0

C.4 Connect to the Internet

 ; 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
     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.
     ; IE3 not installed
     MessageBox MB_OK|MB_ICONINFORMATION "Please connect to the internet now."
   Pop $R0

C.5 Get Installer Filename

 System::Call 'kernel32::GetModuleFileName(p 0, t .R0, i ${NSIS_MAX_STRLEN}) i.r1'
 ;$R0 will contain the installer filename

C.6 Prevent Multiple Instances

Put the following code in your .onInit function:

 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."

'myMutex' must be replaced by a unique value!

C.7 More

You can find more useful scripts on the NSIS Wiki, the NSIS forum and the NSIS development page.

Previous | Contents | Next

SourceForge Logo