Membuat Installer (NSIS Installer) VB 6.0 + Crystal Repoprt

Attention : For dummy Programmer only

“Bingung nih mo buat installan aplikasi yg udah kubuat!!”. Aku dah coba cari di Om google yang muncul sih banyak banget tapi yang free sedikit sekali. Dari beberapa yang free akhirnya aku memutuskan untuk menggunakan NSIS Installer. Setalah aku donlot NSIS-nya dan aku install aku jadi tambah bingung lagi gimana cara menggunakannya? huh’ aku coba baca sedikit manualnya ternyata membuatnya menggunakan script 😦 . Trus dari bawaannya ada sample-nya. Aku coba untuk pelajari scriptnya ternyata menyenangkan juga, jadi tambah semangat nih 🙂 .

Aku dah buat sebuah aplikasi dari VB Classic dengan Database Access + crystal report kemudian aku dah compile menjadi *.exe. Pada NSIS samplenya tidak menyertakan cara mendistribusikan crystal report. Trus aku coba baca help dicrystalnya juga gak ada huh’ menyebalkan… tapi coba dibrowse pada folder Windows $ystem32 ada file crystal32.ocx dan crpe32.dll keduanya mempunyai Crsytal32.dep dan crpe32.dep. Pada keterangan didalamnya ada keterangan file-file apa aja yang dibutuhkan untuk mendistibusikan runtime Crsytal. Sip deh, aku langsung coba aja tuh untuk mempraktekannya dan aku compile dgn NSIS yg scriptnya dah aku includekan runtime crystal. Jadi lah sebuah installer dan langsung aku test pada komputer yg belum terinstall aplikasi vb & crystal. Wow… Sukses dan berjalan dengan mulus…

Dibawah ini adalah contoh NSIS Script yang ku buat.

; Mail Label.exe installer
; Written by Ahmad Nasrul
; Created date : April 2008  

;-------------------------------------------------
; BEGIN HERE
;-------------------------------------------------

; Include Modern UI
 !include "MUI.nsh"
 !include "Library.nsh"
;----------------------------------------

; General

; Name and file
 Name "Mail Label"
 OutFile "Label_setup-1.0.exe"

; default installer folder
 InstallDir "$PROGRAMFILES\Mail Label"

; Get installation folder from the registry if avalaible
 InstallDirRegKey HKCU "Software\Mail Label.exe" ""

;Vista redirects $SMPROGRAMS to all users without this
  RequestExecutionLevel admin

;--------------------------------
;Variables

Var MUI_TEMP
  Var STARTMENU_FOLDER
  Var ALREADY_INSTALLED

; ---------------------------------------------------
; Interface setting
 !define MUI_ICON "setup_icon.ico"
 !define MUI_UNICON "setup_icon.ico"
 !define MUI_HEADERIMAGE
 !define MUI_HEADERIMAGE_BITMAP "D:\My Documents\My Project\mailLabel\header_setup.bmp" ; optional
 !define MUI_ABORTWARNING

;---------------------------------------------------
; Pages

; Language selection dialog setting
 ; Remember the installer language
 ;!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
 ;!define MUI_LANGDLL_REGISTRY_KEY "Software\Mail Label"
 ;!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
; ---------------------------------------------------
 ;Start Menu Folder Page Configuration
 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU"
 !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\Mail Label"
 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
 !define MUI_FINISHPAGE_RUN "$INSTDIR\Mail Label.exe"

!insertmacro MUI_PAGE_WELCOME
 !insertmacro MUI_PAGE_LICENSE "License.txt"
 !insertmacro MUI_PAGE_DIRECTORY
 !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
 !insertmacro MUI_PAGE_INSTFILES
 !insertmacro MUI_PAGE_FINISH

; Uninstaller
 !insertmacro MUI_UNPAGE_WELCOME
 !insertmacro MUI_UNPAGE_CONFIRM
 !insertmacro MUI_UNPAGE_INSTFILES
 !insertmacro MUI_UNPAGE_FINISH
; --------------------------
; Language
 !insertmacro MUI_LANGUAGE "English"
 ;!insertmacro MUI_LANGUAGE "Indonesian"

; Reserve files
 ;!insertmacro MUI_RESERVEFILE_LANGDLL
; ---------------------------------
; Insaller Section

Section "Mail Label Program" mainProgram
 SetOutPath "$INSTDIR"

IfFileExists "$INSTDIR\Mail Label.exe" 0 new_installation ;Replace Mail Label.exe
 	StrCpy $ALREADY_INSTALLED 1
 new_installation:

; Main Program
 File "Mail Label.exe"
 File "label2x10.rpt"

; Library and Component
 ;Add code here that sets $ALREADY_INSTALLED to a non-zero value if the application is already installed. For example:
 !insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_NOTPROTECTED "runtime\System32\msvbvm60.dll" "$SYSDIR\msvbvm60.dll" "$SYSDIR"
 !insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\oleaut32.dll" "$SYSDIR\oleaut32.dll" "$SYSDIR"
 !insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\olepro32.dll" "$SYSDIR\olepro32.dll" "$SYSDIR"
 !insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\comcat.dll"   "$SYSDIR\comcat.dll"   "$SYSDIR"
 !insertmacro InstallLib DLL    $ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\asycfilt.dll" "$SYSDIR\asycfilt.dll" "$SYSDIR"
 !insertmacro InstallLib TLB    $ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\stdole2.tlb"  "$SYSDIR\stdole2.tlb"  "$SYSDIR"
 !insertmacro InstallLib TLB    $ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\stdole32.tlb"  "$SYSDIR\stdole32.tlb"  "$SYSDIR"

!insertmacro InstallLib REGDLL 	$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\comdlg32.ocx"  "$SYSDIR\comdlg32.ocx"  "$SYSDIR"
 !insertmacro InstallLib REGDLL 	$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\comctl32.dll"  "$SYSDIR\comctl32.dll"  "$SYSDIR"
 !insertmacro InstallLib REGDLL 	$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\mscomctl.ocx"  "$SYSDIR\mscomctl.ocx"  "$SYSDIR"
 !insertmacro InstallLib REGDLL 	$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\GIFanimatorV3.ocx"  "$SYSDIR\GIFanimatorV3.ocx"  "$SYSDIR"

; Additional Runtime DLLs (Crystal Library)
 !insertmacro InstallLib DLL		$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\CRPE32.DLL"  "$SYSDIR\CRPE32.DLL"  "$SYSDIR"
 !insertmacro InstallLib DLL		$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\IMPLODE.DLL"  "$SYSDIR\IMPLODE.DLL"  "$SYSDIR"
 !insertmacro InstallLib DLL		$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\CRPAIG80.DLL"  "$SYSDIR\CRPAIG80.DLL"  "$SYSDIR"
 !insertmacro InstallLib DLL		$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\MSVCRT.DLL"  "$SYSDIR\MSVCRT.DLL"  "$SYSDIR"
 !insertmacro InstallLib DLL		$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\MFC42.DLL"  "$SYSDIR\MFC42.DLL"  "$SYSDIR"

; Crystal report physical Database DLL for Microsoft Access
 !insertmacro InstallLib DLL		$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\p2bdao.DLL"  "$SYSDIR\p2bdao.DLL"  "$SYSDIR"
 !insertmacro InstallLib DLL		$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\p2ctdao.DLL"  "$SYSDIR\p2ctdao.DLL"  "$SYSDIR"
 !insertmacro InstallLib DLL		$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\p2irdao.DLL"  "$SYSDIR\p2irdao.DLL"  "$SYSDIR"
 !insertmacro InstallLib DLL		$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\p2smon.DLL"  "$SYSDIR\p2smon.DLL"  "$SYSDIR"

; Physical Access/OLEDB Database driver
 !insertmacro InstallLib DLL		$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\Crystal\p2soledb.dll"  "$SYSDIR\p2soledb.dll"  "$SYSDIR"
 ; Crystal report control
 !insertmacro InstallLib REGDLL 	$ALREADY_INSTALLED REBOOT_PROTECTED    "runtime\System32\Crystl32.OCX"  "$SYSDIR\Crystl32.OCX"  "$SYSDIR"

; Crystal Export
 ;$WINDIR

; Store installation folder
 WriteRegStr HKCU "Software\Mail Label" "" $INSTDIR
 ;Add uninstall information to Add/Remove Programs
 ;WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Product" "Mail Label" "$INSTDIR\Uninstall.exe"

; Create Unistaller
 WriteUninstaller "$INSTDIR\Uninstall.exe"

!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
 ;Create shortcuts
    CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
    CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
 CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Mail Label.lnk" "$INSTDIR\Mail Label.exe"
 CreateShortCut "$DESKTOP\Mail Label.lnk" "$INSTDIR\Mail Label.exe"
 !insertmacro MUI_STARTMENU_WRITE_END

;MessageBox MB_OK "$SYSDIR"

SectionEnd

;--------------------------------
;Installer Functions

Section "Uninstall"

;Add files here...

Delete "$INSTDIR\Uninstall.exe"
  Delete "$INSTDIR\Mail Label.exe"
  Delete "$INSTDIR\label2x10.rpt"

RMDir "$INSTDIR"

; Uninstall Library
 !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"
 !insertmacro UnInstallLib TLB		SHARED NOREMOVE "$SYSDIR\stdole32.tlb"

!insertmacro UnInstallLib REGDLL 	SHARED NOREMOVE	"$SYSDIR\comdlg32.ocx"
 !insertmacro UnInstallLib REGDLL 	SHARED NOREMOVE "$SYSDIR\comctl32.dll"
 !insertmacro UnInstallLib REGDLL 	SHARED NOREMOVE "$SYSDIR\mscomctl.ocx"
 !insertmacro UnInstallLib REGDLL 	NOTSHARED NOREBOOT_NOTPROTECTED "$SYSDIR\GIFanimatorV3.ocx"

!insertmacro UnInstallLib DLL		SHARED NOREMOVE	"$SYSDIR\CRPE32.DLL"
 !insertmacro UnInstallLib DLL		SHARED NOREMOVE "$SYSDIR\IMPLODE.DLL"
 !insertmacro UnInstallLib DLL		SHARED NOREMOVE "$SYSDIR\CRPAIG80.DLL"
 !insertmacro UnInstallLib DLL		SHARED NOREMOVE "$SYSDIR\MSVCRT.DLL"
 !insertmacro UnInstallLib DLL		SHARED NOREMOVE "$SYSDIR\MFC42.DLL"
 !insertmacro UnInstallLib DLL		SHARED NOREMOVE "$SYSDIR\p2soledb.dll"
 !insertmacro UnInstallLib REGDLL 	SHARED NOREMOVE "$SYSDIR\Crystl32.OCX"

!insertmacro UnInstallLib DLL		SHARED NOREMOVE "$SYSDIR\p2bdao.DLL"
 !insertmacro UnInstallLib DLL		SHARED NOREMOVE "$SYSDIR\p2ctdao.DLL"
 !insertmacro UnInstallLib DLL		SHARED NOREMOVE "$SYSDIR\p2irdao.DLL"
 !insertmacro UnInstallLib DLL		SHARED NOREMOVE "$SYSDIR\p2smon.DLL"

!insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP

Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  Delete "$SMPROGRAMS\$MUI_TEMP\Mail Label.lnk"

;Delete empty start menu parent diretories
  StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"

startMenuDeleteLoop:
 ClearErrors
    RMDir $MUI_TEMP
    GetFullPathName $MUI_TEMP "$MUI_TEMP\.."

IfErrors startMenuDeleteLoopDone

StrCmp $MUI_TEMP $SMPROGRAMS startMenuDeleteLoopDone startMenuDeleteLoop
  startMenuDeleteLoopDone:

DeleteRegKey /ifempty HKCU "Software\Mail Label"
  MessageBox MB_OK "Thank you for using Mail Label."
SectionEnd

;--------------------------------
;Uninstaller Functions

Done.

2 comments

  1. Bisnis Bunda · May 14, 2009

    kalo di vb.net gimana ya?

  2. endang · May 4, 2013

    Postingan yang lagi saya cari akhirnya ketemu juga. Makasih mas atas tulisannya, semoga Allah membalasnya. Sy lg belajar vb+postgre+cr7. Apa bisa dibuat setupannya. Terima kasih

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s