How to install the VB6 runtimes: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (comcat32.dll -> comcat.dll)
m ("UpgradeDLl" -> "UpgradeDLL".)
Line 66: Line 66:


== NSIS 2.0 and older ==
== NSIS 2.0 and older ==
Still using NSIS 2.0? You can use the UpgradeDLl macro and a few function to install and uninstall the VB6 runtimes. Note that the NSIS 2.01 system above is recommended and provides a better and more stable installation method.
Still using NSIS 2.0? You can use the UpgradeDLL macro and a few function to install and uninstall the VB6 runtimes. Note that the NSIS 2.01 system above is recommended and provides a better and more stable installation method.


=== Description ===
=== Description ===

Revision as of 22:45, 21 June 2005

Author: sunjammer (talk, contrib)


NSIS 2.01 and later

NSIS 2.01 has a new library system that makes it easy to install files like the VB6 runtimes. This script and more information is also available in appendix B of the users manual.

Description

The correct version of the following files should be stored in your script folder (or modify the paths to the local files if you want to use another folder):

  • msvbvm60.dll
  • oleaut32.dll
  • olepro32.dll
  • oleaut32.dll
  • comcat.dll
  • asycfilt.dll
  • stdole2.tlb

A Microsoft article that explains how to obtain these files is available.

To ask the user for a reboot if required, use the Modern UI with a Finish page or use IfRebootFlag and make your own page or message box.

The Script

!include Library.nsh
 
 Var ALREADY_INSTALLED
 
 Section "-Install VB6 runtimes"
 
   ;Add code here that sets $ALREADY_INSTALLED to a non-zero value if the
   ;application is already installed. For example:
 
   IfFileExists "$INSTDIR\MyApp.exe" 0 new_installation
   ;Replace MyApp.exe with your application filename
     StrCpy $ALREADY_INSTALLED 1
   new_installation:
 
   !insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_NOTPROTECTED \
     "msvbvm60.dll" "$SYSDIR\msvbvm60.dll" "$SYSDIR"
   !insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_PROTECTED \
     "oleaut32.dll" "$SYSDIR\oleaut32.dll" "$SYSDIR"
   !insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_PROTECTED \
     "olepro32.dll" "$SYSDIR\olepro32.dll" "$SYSDIR"
   !insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_PROTECTED \
     "comcat.dll"   "$SYSDIR\comcat.dll"   "$SYSDIR"
   !insertmacro InstallLib DLL    $ALREADY_INSTALLED REBOOT_PROTECTED \
     "asycfilt.dll" "$SYSDIR\asycfilt.dll" "$SYSDIR"
   !insertmacro InstallLib TLB    $ALREADY_INSTALLED REBOOT_PROTECTED \
     "stdole2.tlb"  "$SYSDIR\stdole2.tlb"  "$SYSDIR"
 
 SectionEnd
 
 Section "-un.Uninstall VB6 runtimes"
 
   !insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\msvbvm60.dll"
   !insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\oleaut32.dll" 
   !insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\olepro32.dll"
   !insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\comcat.dll" 
   !insertmacro UnInstallLib DLL    SHARED NOREMOVE "$SYSDIR\asycfilt.dll"
   !insertmacro UnInstallLib TLB    SHARED NOREMOVE "$SYSDIR\stdole2.tlb"
 
 SectionEnd

You can use similar code to install common VB6 ActiveX controls (such as the controls for Windows Common Controls).

NSIS 2.0 and older

Still using NSIS 2.0? You can use the UpgradeDLL macro and a few function to install and uninstall the VB6 runtimes. Note that the NSIS 2.01 system above is recommended and provides a better and more stable installation method.

Description

The best way to install the VB6 runtimes using NSIS 2.0 is to use the UpgradeDLL macro to upgrade the DLL files and the AddSharedDLL function macro when installing the software for the first time to increment the shared DLL count.

During the uninstallation, use the un.DecrementSharedDLL function below to decrement the shared DLL count (never remove the files, because the shared DLL count is not reliable enough for such imporant files).

The correct version of the following files should be stored in your script folder (or modify the paths to the local files if you want to use another folder):

  • msvbvm60.dll
  • oleaut32.dll
  • olepro32.dll
  • oleaut32.dll
  • comcat.dll
  • asycfilt.dll
  • stdole2.tlb

A Microsoft article that explains how to obtain these files is available.

To ask the user for a reboot if required, use the Modern UI with a Finish page or use IfRebootFlag and make your own page or message box.

The Script

!include "UpgradeDLL.nsh"
 
Section "-Install VB6 runtimes"
 
  !insertmacro UpgradeDLL comcat.dll $SYSDIR\Comcat.dll $SYSDIR
  !insertmacro UpgradeDLL msvbvm60.dll $SYSDIR\Msvbvm60.dll $SYSDIR
  !insertmacro UpgradeDLL oleaut32.dll $SYSDIR\Oleaut32.dll $SYSDIR
  !insertmacro UpgradeDLL olepro32.dll $SYSDIR\Olepro32.dll $SYSDIR
 
  !define UPGRADEDLL_NOREGISTER
    !insertmacro UpgradeDLL asycfilt.dll $SYSDIR\asycfilt.dll $SYSDIR
    !insertmacro UpgradeDLL stdole2.tlb $SYSDIR\stdole2.tlb $SYSDIR
  !undef UPGRADEDLL_NOREGISTER
 
  ;Only increase DLL count on new installation
  ;Replace MyApp.exe with your application filename
  ;(or use another detection method)
 
  IfFileExists $INSTDIR\MyApp.exe skipAddSharedDLL
    Push $SYSDIR\asycfilt.dll
    Call AddSharedDLL
    Push $SYSDIR\comcat.dll
    Call AddSharedDLL
    Push $SYSDIR\msvbvm60.dll
    Call AddSharedDLL
    Push $SYSDIR\oleaut32.dll
    Call AddSharedDLL
    Push $SYSDIR\olepro32.dll
    Call AddSharedDLL
    Push $SYSDIR\stdole2.tlb
    Call AddSharedDLL
  skipAddSharedDLL:
 
SectionEnd
 
Section "-un.Uninstall VB6 runtimes"
 
  Push $SYSDIR\asycfilt.dll
  Call un.DecrementSharedDLL
  Push $SYSDIR\comcat.dll
  Call un.DecrementSharedDLL
  Push $SYSDIR\msvbvm60.dll
  Call un.DecrementSharedDLL
  Push $SYSDIR\oleaut32.dll
  Call un.DecrementSharedDLL
  Push $SYSDIR\olepro32.dll
  Call un.DecrementSharedDLL
  Push $SYSDIR\stdole2.tlb
  Call un.DecrementSharedDLL
 
SectionEnd
 
Function AddSharedDLL
  Exch $R1
  Push $R0
    ReadRegDword $R0 HKLM \
      Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1
    IntOp $R0 $R0 + 1
    WriteRegDWORD HKLM \
      Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1 $R0
   Pop $R0
   Pop $R1
 FunctionEnd
 
Function un.DecrementSharedDLL
  Exch $R1
  Push $R0
  ReadRegDword $R0 HKLM \
    Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1
  StrCmp $R0 "" done
    IntOp $R0 $R0 - 1
    IntCmp $R0 0 rk rk uk
    rk:
      DeleteRegValue HKLM \
        Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1
      Goto done
    uk:
      WriteRegDWORD HKLM \
        Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1 $R0
      Goto done
  done:
  Pop $R0
  Pop $R1
FunctionEnd

You can use similar code to install common VB6 ActiveX controls (such as the controls for Windows Common Controls).