Previous | Contents | Next

C.4 How to install the VB6 runtimes

The best way to install the VB6 runtimes is to use the UpgradeDLL macro to upgrade the DLL files and the AddSharedDLL function to increment the shared DLL count.

Use the Modern UI with a Finish page to ask for a reboot if required or use IfRebootFlag and make your own page or messagebox.

To get the VB6 runtime files, you can extract the files from vbrun60sp5.exe using any archiver that supports CAB compression or, if you have installed the latest version, copy the the files from the System folder. You need the following files:

Asycfilt.dll
Comcat.dll
Msvbvm60.dll
Oleaut32.dll
Olepro32.dll
Stdole2.tlb

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

!include "UpgradeDLL.nsh"

!define VBFILESDIR "C:\Windows\System" ;Location of VB6 runtime files

Section "Install VB DLLs"

  !insertmacro UpgradeDLL ${VBFILESDIR}\Comcat.dll $SYSDIR\Comcat.dll $SYSDIR
  !insertmacro UpgradeDLL ${VBFILESDIR}\Msvbvm60.dll $SYSDIR\Msvbvm60.dll $SYSDIR
  !insertmacro UpgradeDLL ${VBFILESDIR}\Oleaut32.dll $SYSDIR\Oleaut32.dll $SYSDIR
  !insertmacro UpgradeDLL ${VBFILESDIR}\Olepro32.dll $SYSDIR\Olepro32.dll $SYSDIR

  !define UPGRADEDLL_NOREGISTER
    !insertmacro UpgradeDLL ${VBFILESDIR}\Asycfilt.dll $SYSDIR\Asycfilt.dll $SYSDIR
    !insertmacro UpgradeDLL ${VBFILESDIR}\Stdole2.tlb $SYSDIR\Stdole2.tlb $SYSDIR
  !undef UPGRADEDLL_NOREGISTER

  ;Only iease DLL count on new installation
  ;Replace myprog.exe or use another detection method
  IfFileExists $INSTDIR\myprog.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 "Uninstall"

  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
  done:
  Pop $R0
  Pop $R1
FunctionEnd

Previous | Contents | Next