How to install the VB6 runtimes: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Adding new author and category links.)
(update to use new VB6RunTime.nsh header file)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{PageAuthor|sunjammer}}
A new VB6RunTime.nsh header file is available for the setup of the VB6 run-time files. To obtain the latest run-time files, download [http://nsis.sourceforge.net/vb6runtime.zip vb6runtime.zip] and extract this file.


== 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 [http://support.microsoft.com/default.aspx?scid=kb;en-us;290887 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 ===
<highlight-nsis>
<highlight-nsis>
!include Library.nsh
!include VB6RunTime.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
</highlight-nsis>
You can use similar code to install common VB6 ActiveX controls (such as the controls for Windows Common Controls).


== NSIS 2.0 and older ==
Var AlreadyInstalled
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 ===
Section "-Install VB6 run-time files"
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).
  ;Add code here that sets $AlreadyInstalled to a non-zero value
  ;if the application is already installed. For example:
  ;(Replace MyApp.exe with your application filename)
  IfFileExists "$INSTDIR\MyApp.exe" 0 new_installation
    StrCpy $AlreadyInstalled 1
  new_installation:


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):
  ;Replace C:\vb6runtimes with the location of the files
 
   !insertmacro VB6RunTimeInstall C:\vb6runtimes $AlreadyInstalled
*msvbvm60.dll
*oleaut32.dll
*olepro32.dll
*oleaut32.dll
*comcat.dll
*asycfilt.dll
*stdole2.tlb
 
A [http://support.microsoft.com/default.aspx?scid=kb;en-us;290887 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 ===
<highlight-nsis>
!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
SectionEnd


Section "-un.Uninstall VB6 runtimes"
Section "-un.Uninstall VB6 run-time files"


  Push $SYSDIR\asycfilt.dll
!insertmacro VB6RunTimeUnInstall
  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
SectionEnd
</highlight-nsis>


Function AddSharedDLL
Remarks:
  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
</highlight-nsis>
You can use similar code to install common VB6 ActiveX controls (such as the controls for Windows Common Controls).


[[Category:Tutorials]]
* You may have to install additional files for such Visual Basic application to work, such as OCX files for user interface controls.
* Installation of the run-time files requires Administrator or Power User privileges. Use the Multi-User header file to verify whether these privileges are available.
Add a Modern UI finish page or another check (see IfRebootFlag) to allow the user to restart the computer when necessary.

Latest revision as of 20:26, 22 April 2008

A new VB6RunTime.nsh header file is available for the setup of the VB6 run-time files. To obtain the latest run-time files, download vb6runtime.zip and extract this file.

!include VB6RunTime.nsh
 
Var AlreadyInstalled
 
Section "-Install VB6 run-time files"
 
  ;Add code here that sets $AlreadyInstalled to a non-zero value
  ;if the application is already installed. For example:
  ;(Replace MyApp.exe with your application filename)
  IfFileExists "$INSTDIR\MyApp.exe" 0 new_installation 
    StrCpy $AlreadyInstalled 1
  new_installation:
 
  ;Replace C:\vb6runtimes with the location of the files
  !insertmacro VB6RunTimeInstall C:\vb6runtimes $AlreadyInstalled
 
SectionEnd
 
Section "-un.Uninstall VB6 run-time files"
 
 !insertmacro VB6RunTimeUnInstall
 
SectionEnd

Remarks:

  • You may have to install additional files for such Visual Basic application to work, such as OCX files for user interface controls.
  • Installation of the run-time files requires Administrator or Power User privileges. Use the Multi-User header file to verify whether these privileges are available.

Add a Modern UI finish page or another check (see IfRebootFlag) to allow the user to restart the computer when necessary.