Installing Microsoft Data Access Components

From NSIS Wiki
Jump to navigationJump to search
Author: zimsms (talk, contrib)


Description

I have supplied the following since most people installing the Microsoft Data Access Components, only choose to install the English version, which may be incorrect for their end users machine. This also contains the proper error handling, which most installs do not use.

This 'Template' can be used for pretty much any Microsoft download with a few modifications. I have cut most of the 'extra' languages out to keep the example simple.

THIS IS NOT A COMPLETE SCRIPT, IT IS INTENDED TO ASSIST THOSE REQUIRING THE INSTALLATION OF THE MICROSOFT DATA ACCESS COMPONENTS FOR A MULTI-LANGUAGE INSTALL.

Defines

; Microsoft Data Access Components 2.8
; English
!define URL_MDAC28_1033 "http://download.microsoft.com/download/c/d/f/cdfd58f1-3973-4c51-8851-49ae3777586f/MDAC_TYP.EXE"
; German
!define URL_MDAC28_1031 "http://download.microsoft.com/download/a/b/9/ab965707-fbab-48bc-8c33-a4cfd44255c6/MDAC_TYP.EXE"
; Spanish
!define URL_MDAC28_1034 "http://download.microsoft.com/download/b/3/c/b3cbdb35-80a5-4fa2-a9af-ad84d1757f6b/MDAC_TYP.EXE"
; French
!define URL_MDAC28_1036 "http://download.microsoft.com/download/d/8/6/d86f23a0-628a-4fea-9907-5ef1304d8124/MDAC_TYP.EXE"
; Portuguese
!define URL_MDAC28_2070 "http://download.microsoft.com/download/e/6/a/e6ad297b-7207-4bf0-9322-b8f8cf893346/MDAC_TYP.EXE"
; Portuguese (Brazil)
!define URL_MDAC28_1046 "http://download.microsoft.com/download/1/a/4/1a47382d-18f3-41d4-b92c-74db27d5944b/MDAC_TYP.EXE"
; Chinese (Simplified)
!define URL_MDAC28_2052 "http://download.microsoft.com/download/8/b/6/8b6198c0-fe96-4811-9d81-d5c76dd5fea8/MDAC_TYP.EXE"

If you need one not listed above you will have to visit the Microsoft Download site, select the language you are after and scan the page source to obtain the link.

Variables

Var "LANGUAGE_DLL_TITLE"
Var "LANGUAGE_DLL_INFO"
Var "URL_MDAC28"
Var "OSLANGUAGE"
Var "MDAC28_RETURN_CODE"

Language Strings

  LangString DESC_REMAINING ${LANG_ENGLISH} " (%d %s%s remaining)"
  LangString DESC_PROGRESS ${LANG_ENGLISH} "%d.%01dkB/s" ;"%dkB (%d%%) of %dkB @ %d.%01dkB/s"
  LangString DESC_PLURAL ${LANG_ENGLISH} "s"
  LangString DESC_HOUR ${LANG_ENGLISH} "hour"
  LangString DESC_MINUTE ${LANG_ENGLISH} "minute"
  LangString DESC_SECOND ${LANG_ENGLISH} "second"
  LangString DESC_CONNECTING ${LANG_ENGLISH} "Connecting..."
  LangString DESC_DOWNLOADING ${LANG_ENGLISH} "Downloading %s"
  LangString DESC_SHORTMDAC28 ${LANG_ENGLISH} "Microsoft Data Access Components 2.8"
  LangString DESC_LONGMDAC28 ${LANG_ENGLISH} "Microsoft Data Access Components 2.8"
  LangString DESC_MDAC28_DECISION ${LANG_ENGLISH} "$(DESC_SHORTMDAC28) is required.$\nIt is strongly advised that you install$\n$(DESC_SHORTMDAC28) before continuing.$\nIf you choose to continue, you will need to connect$\nto the internet before proceeding.$\nWould you like to continue with the installation?"
  LangString SEC_MDAC28 ${LANG_ENGLISH} "$(DESC_SHORTMDAC28) "
  LangString DESC_INSTALLING ${LANG_ENGLISH} "Installing"
  LangString DESC_DOWNLOADING1 ${LANG_ENGLISH} "Downloading"
  LangString DESC_DOWNLOADFAILED ${LANG_ENGLISH} "Download Failed:"
  LangString ERROR_MDAC28_DUPLICATE_INSTANCE ${LANG_ENGLISH} "The $(DESC_SHORTMDAC28) Installer is already running."
  LangString ERROR_NOT_ADMINISTRATOR ${LANG_ENGLISH} "$(DESC_000022)"
  LangString ERROR_INVALID_PLATFORM ${LANG_ENGLISH} "$(DESC_000023)"
  LangString DESC_MDAC28_TIMEOUT ${LANG_ENGLISH} "The installation of the $(DESC_SHORTMDAC28) has timed out."
  LangString ERROR_MDAC28_INVALID_PATH ${LANG_ENGLISH} "The $(DESC_SHORTMDAC28) Installation$\nwas not found in the following location:$\n"
  LangString ERROR_MDAC28_FATAL ${LANG_ENGLISH} "A fatal error occurred during the installation$\nof the $(DESC_SHORTMDAC28)."
  LangString FAILED_MDAC28_INSTALL ${LANG_ENGLISH} "The installation of $(PRODUCT_NAME) will$\ncontinue. However, it may not function properly$\nuntil $(DESC_SHORTMDAC28)$\nis installed."

Section

  Section $(SEC_MDAC28) SECMDAC28
    SectionIn RO
    IfSilent lbl_IsSilent
    !define MDAC28FILESDIR "Common\Files\MSNET"
    StrCpy $MDAC28_RETURN_CODE "0"
!ifdef MDAC28_ONCD_1033
    StrCmp "$OSLANGUAGE" "1033" 0 lbl_Not1033
    SetOutPath "$PLUGINSDIR"
    file /r "${MDAC28FILESDIR}\MDAC_TYP_1033.exe"
    DetailPrint "$(DESC_INSTALLING) $(DESC_SHORTMDAC28)..."
    Banner::show /NOUNLOAD "$(DESC_INSTALLING) $(DESC_SHORTMDAC28)..."
    nsExec::ExecToStack '"$PLUGINSDIR\MDAC_TYP_1033.exe" /q /C:"setup /QNT"'
    pop $MDAC28_RETURN_CODE
    Banner::destroy
    SetRebootFlag true
    Goto lbl_NoDownloadRequired
    lbl_Not1033:
!endif
; Insert Other language blocks here
 
    ; the following Goto and Label is for consistencey.
    Goto lbl_DownloadRequired
    lbl_DownloadRequired:
    DetailPrint "$(DESC_DOWNLOADING1) $(DESC_SHORTMDAC28)..."
    MessageBox MB_ICONEXCLAMATION|MB_YESNO|MB_DEFBUTTON2 "$(DESC_MDAC28_DECISION)" /SD IDNO IDYES +2 IDNO 0
    abort
    ; "Downloading Microsoft Data Access Components 2.8"
    AddSize 153600
    nsisdl::download /TRANSLATE "$(DESC_DOWNLOADING)" "$(DESC_CONNECTING)" \
       "$(DESC_SECOND)" "$(DESC_MINUTE)" "$(DESC_HOUR)" "$(DESC_PLURAL)" \
       "$(DESC_PROGRESS)" "$(DESC_REMAINING)" \
       /TIMEOUT=30000 "$URL_MDAC28" "$PLUGINSDIR\MDAC_TYP.exe"
    Pop $0
    StrCmp "$0" "success" lbl_continue
    DetailPrint "$(DESC_DOWNLOADFAILED) $0"
    Abort
 
    lbl_continue:
      DetailPrint "$(DESC_INSTALLING) $(DESC_SHORTMDAC28)..."
      Banner::show /NOUNLOAD "$(DESC_INSTALLING) $(DESC_SHORTMDAC28)..."
      nsExec::ExecToStack '"$PLUGINSDIR\MDAC_TYP.exe" /q /C:"setup /QNT"'
      pop $MDAC28_RETURN_CODE
      Banner::destroy
      SetRebootFlag true
      ; silence the compiler
      Goto lbl_NoDownloadRequired
      lbl_NoDownloadRequired:
 
      ; obtain any error code and inform the user ($MDAC28_RETURN_CODE)
      ; If nsExec is unable to execute the process,
      ; it will return "error"
      ; If the process timed out it will return "timeout"
      ; else it will return the return code from the executed process.
      StrCmp "$MDAC28_RETURN_CODE" "" lbl_NoError
      StrCmp "$MDAC28_RETURN_CODE" "0" lbl_NoError
      StrCmp "$MDAC28_RETURN_CODE" "3010" lbl_NoError
      StrCmp "$MDAC28_RETURN_CODE" "8192" lbl_NoError
      StrCmp "$MDAC28_RETURN_CODE" "error" lbl_Error
      StrCmp "$MDAC28_RETURN_CODE" "timeout" lbl_TimeOut
      ; It's a MDAC Error
      StrCmp "$MDAC28_RETURN_CODE" "4101" lbl_Error_DuplicateInstance
      StrCmp "$MDAC28_RETURN_CODE" "4097" lbl_Error_NotAdministrator
      StrCmp "$MDAC28_RETURN_CODE" "1633" lbl_Error_InvalidPlatform lbl_FatalError
      ; all others are fatal
 
    lbl_Error_DuplicateInstance:
    DetailPrint "$(ERROR_MDAC28_DUPLICATE_INSTANCE)"
    GoTo lbl_Done
 
    lbl_Error_NotAdministrator:
    DetailPrint "$(ERROR_NOT_ADMINISTRATOR)"
    GoTo lbl_Done
 
    lbl_Error_InvalidPlatform:
    DetailPrint "$(ERROR_INVALID_PLATFORM)"
    GoTo lbl_Done
 
    lbl_TimeOut:
    DetailPrint "$(DESC_MDAC28_TIMEOUT)"
    GoTo lbl_Done
 
    lbl_Error:
    DetailPrint "$(ERROR_MDAC28_INVALID_PATH)"
    GoTo lbl_Done
 
    lbl_FatalError:
    DetailPrint "$(ERROR_MDAC28_FATAL)[$MDAC28_RETURN_CODE]"
    GoTo lbl_Done
 
    lbl_Done:
    DetailPrint "$(FAILED_MDAC28_INSTALL)"
    lbl_NoError:
    lbl_IsSilent:
  SectionEnd
 
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${SECMDAC28} $(DESC_LONGMDAC28)
!insertmacro MUI_FUNCTION_DESCRIPTION_END

This requires some setup in .OnInit:

Function .onInit
  StrCpy $LANGUAGE_DLL_TITLE "Installer Language"
  StrCpy $LANGUAGE_DLL_INFO "Please select a language:"
  StrCpy $URL_MDAC28 "${URL_MDAC28_1033}"
  StrCpy $OSLANGUAGE "1033"
 
; Insert other Language Blocks Here
 
  !define MUI_LANGDLL_WINDOWTITLE "$LANGUAGE_DLL_TITLE"
  !define MUI_LANGDLL_INFO "$LANGUAGE_DLL_INFO"
  !insertmacro MUI_LANGDLL_DISPLAY
  !undef MUI_LANGDLL_WINDOWTITLE
  !undef MUI_LANGDLL_INFO
  InitPluginsDir
  SetOutPath "$PLUGINSDIR"
  File "Common\Plugins\*.*"
  File /r "${NSISDIR}\Plugins\*.*"
FunctionEnd

Macros

!macro IsMDAC28Installed
   push $0
   push $1
   ; format 2.80.1022.3
   ReadRegStr $0 HKLM "SOFTWARE\Microsoft\DataAccess" "Version"
   StrCmp "$0" "" _MDAC28notInstalled
   StrCpy $1 "$0" 1
   IntCmp $1 "2" _MDAC2 _MDAC28notInstalled _MDAC28Installed
   _MDAC2:
   StrCpy $1 "$0" 1 2
   IntCmp "$1" "8" _MDAC28Installed _MDAC28notInstalled _MDAC28Installed
 
   _MDAC28notInstalled:
   StrCpy $0 "0"
   Goto +3
   _MDAC28Installed:
   StrCpy $0 "1"
   ; done
   pop $1
   exch $0
!macroend

I test for IsMDAC28Installed by defining a custom function overriding GUI Init, and set the section selection accordingly. Hopefully this was of use to you. Cheers!