Coding4ever’s Blog

Just coding… coding… and coding… because coding should be fun :)

Membuat Paket Instalasi Vb + Mysql Dengan Inno Setup

| Comments

Membuat paket instalasi yang mudah untuk aplikasi yang akan kita distribusikan memang gampang-gampang susah, gampang bagi kita untuk membuatnya hanya dengan menggunakan Package & Deployment Wizard.

Package & Deployment Wizard merupakan tool installer bawaan yang sudah disediakan oleh visual basic, tetapi apakah hasilnya akan cukup memudahkan bagi klien apalagi jika aplikasi yang kita buat menggunakan database yang membutuhkan konfigurasi atau setting-setting yang lumayan banyak pada saat instalasi, seperti MySQL atau Firebird (Maaf ya Ms Access enggak termasuk :D).

Atau kita mencukupkan untuk membuat panduan instalasi yang dibagi menjadi beberapa bagian :

  1. Instalasi Program

  2. Instalasi Database Server (ex. MySQL/Firebird) + Konfigurasi

  3. Install Driver ODBC

  4. Mengcopy database/undump script sql

Atau kita ingin sedikit memaksakan diri dengan membuat paket instalasi yang mudah yang hanya dengan 6 kali klik bisa menyelesaikan semua masalah diatas. Jika iya kita langsung saja mempersiapkan tool-tool yang dibutuhkan :

  1. Inno Setup

  2. MySQL versi noninstall disesuaikan dengan versi MySQL yang terinstall di komputer Anda

  3. Connector ODBC yang sudah terinstall biasanya ada di C:\Program Files\MySQL\Connector ODBC 5.1

  4. Database yang sudah di backup/dump

Adapun versi yang terinstall di komputer saya :

  1. Inno Setup 5.0.8

  2. MySQL Server: 5.1.36-community

  3. Connector ODBC 5.1

Lakukan backup/dump database dengan cara :

  1. Aktifkan dos console

  2. Masuk ke folder instalasi MySQL misal C:\Program Files\MySQL\MySQL Server 5.1\bin

  3. kemudian ketikkan perintah: mysqldump -unama_user -ppassword_user –routines nama_database > c:\nama_database.sql

Parameter –routines wajib Anda ketikkan jika database Anda mempunyai prosedur/fungsi. Persiapan terakhir untuk struktur folder saya buat seperti berikut :

Untuk keterangan lebih lanjut skrip inno setup silahkan baca manualnya. Contoh skrip instalasi lengkap :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
;Skrip instalasi by k4m4r82
;http://coding4ever.wordpress.com/
[Setup]
AppName=Sistem Pembelian Bahan Baku PT. ALBASI
AppVerName=Sistem Pembelian Bahan Baku PT. ALBASI Versi 1.0.0.50
AppPublisher=K4m4r82's Laboratory
AllowCancelDuringInstall = yes
DefaultDirName={pf}\PT ALBASI
DefaultGroupName=PT ALBASI
Compression = lzma
SolidCompression = yes
OutputBaseFilename=SetupAlbasiServer
AllowNoIcons = yes
AlwaysRestart = no
AlwaysShowComponentsList = no
DisableProgramGroupPage = yes
AppendDefaultDirName = yes
CreateUninstallRegKey = yes
DisableStartupPrompt = yes
LanguageDetectionMethod=none
ShowLanguageDialog=no
Uninstallable = yes
UninstallFilesDir={app}\uninst
UninstallDisplayIcon={app}\Albasi.exe,0
UninstallDisplayName=Sistem Pembelian Bahan Baku PT. ALBASI
WindowVisible = no
AppCopyright=Copyright © 2009. K4m4r82's Laboratory
FlatComponentsList = yes
PrivilegesRequired = admin
VersionInfoVersion=1.0.0.50
SetupIconFile=Setup.ico
WizardImageFile=SetupModern21.bmp
WizardSmallImageFile=SetupModernSmall21.bmp

[Languages]
Name: ina; MessagesFile: compiler:Indonesia.isl
Name: en; MessagesFile: compiler:Default.isl

[Tasks]
Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Flags: unchecked
Name: quicklaunchicon; Description: {cm:CreateQuickLaunchIcon}; GroupDescription: {cm:AdditionalIcons}; Flags: unchecked
Name: installmysql; Description: "Install MySQL"; GroupDescription: "Proses tambahan:"; Flags: checkedonce

[Files]
;Visual Basic Runtime
Source: dll&ocx\VB6STKIT.DLL; DestDir: {sys}; Flags: uninsneveruninstall onlyifdoesntexist
Source: dll&ocx\COMCAT.DLL; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\stdole2.tlb; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regtypelib
Source: dll&ocx\asycfilt.dll; DestDir: {sys}; Flags: uninsneveruninstall onlyifdoesntexist
Source: dll&ocx\olepro32.dll; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\oleaut32.dll; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\msvbvm60.dll; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist

;daftar file MySQL
Source: mysql-5.1.36-win32\bin\*; DestDir: {app}\mysql\bin; Flags: ignoreversion; Tasks: installmysql
Source: mysql-5.1.36-win32\Docs\*; DestDir: {app}\mysql\Docs; Flags: ignoreversion; Tasks: installmysql
Source: mysql-5.1.36-win32\lib\*; DestDir: {app}\mysql\lib; Flags: ignoreversion recursesubdirs; Tasks: installmysql
Source: mysql-5.1.36-win32\share\*; DestDir: {app}\mysql\share; Flags: ignoreversion recursesubdirs; Tasks: installmysql
Source: mysql-5.1.36-win32\data\*; DestDir: {app}\mysql\data; Flags: ignoreversion recursesubdirs uninsneveruninstall; Tasks: installmysql
Source: mysql-5.1.36-win32\*; DestDir: {app}\mysql; Flags: ignoreversion; Tasks: installmysql

;daftar file MySQL ODBC 5.1
Source: "C:\Program Files\MySQL\Connector ODBC 5.1\myodbc5.dll"; DestDir: {sys}; Flags: onlyifdoesntexist
Source: "C:\Program Files\MySQL\Connector ODBC 5.1\myodbc5S.dll"; DestDir: {sys}; Flags: onlyifdoesntexist
Source: "C:\Program Files\MySQL\Connector ODBC 5.1\myodbc5.lib"; DestDir: {sys}; Flags: onlyifdoesntexist
Source: "C:\Program Files\MySQL\Connector ODBC 5.1\myodbc5S.lib"; DestDir: {sys}; Flags: onlyifdoesntexist
Source: "C:\Program Files\MySQL\Connector ODBC 5.1\myodbc-installer.exe"; DestDir: {sys}; Flags: onlyifdoesntexist

;My Application Runtime
Source: main\Albasi.exe.manifest; DestDir: {app}; Flags: ignoreversion
Source: main\Albasi.exe; DestDir: {app}; Flags: ignoreversion
Source: main\albasi.sql; DestDir: {app}\mysql\bin; Flags: ignoreversion
Source: main\exec.cmd; DestDir: {app}\mysql\bin; Flags: ignoreversion

Source: dll&ocx\MSMASK32.OCX; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\cTreeOpt6.ocx; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\Comdlg32.ocx; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\vbalDTab6.ocx; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\MSCOMCT2.OCX; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\MyTextBox.ocx; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\LVbuttons.ocx; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\vbalExpBar6.ocx; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\MSCOMCTL.OCX; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\vbalIml6.ocx; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\cPopMenu6.ocx; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\cNewMenu6.dll; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\scrrun.dll; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\vbalMDITabs6.dll; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist
Source: dll&ocx\SSubTmr6.dll; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regserver onlyifdoesntexist

Source: dll&ocx\msado21.tlb; DestDir: {sys}; Flags: uninsneveruninstall sharedfile regtypelib

[Icons]
Name: {group}\Sistem Pembelian Bahan Baku PT. ALBASI; Filename: {app}\Albasi.exe; WorkingDir: {app}
Name: {userdesktop}\Sistem Pembelian Bahan Baku PT. ALBASI; Filename: {app}\Albasi.exe; WorkingDir: {app}; Tasks: desktopicon
Name: {userappdata}\Microsoft\Internet Explorer\Quick Launch\Sistem Pembelian Bahan Baku PT. ALBASI; Filename: {app}\Albasi.exe; WorkingDir: {app}; Tasks: quicklaunchicon

[INI]
Filename: {app}\mysql\my.ini; Section: mysqld; Key: basedir; String: {app}\mysql; Tasks: installmysql
Filename: {app}\mysql\my.ini; Section: mysqld; Key: datadir; String: {app}\mysql\data; Tasks: installmysql

Filename: {app}\infoProgram.ini; Section: Sistem; Key: serverName; String: "127.0.0.1"
Filename: {app}\infoProgram.ini; Section: Sistem; Key: dbName; String: "albasi"

[Run]
;install service MySQL
Filename: "{app}\mysql\bin\mysqld.exe"; Parameters: "install ""MySQL"""; StatusMsg: "Sedang menginstall service MySQL ..."; Flags: runhidden; MinVersion: 0,5.01.2600sp2; Tasks: installmysql

;jalankan service MySQL
Filename: {sys}\net.exe; Parameters: "start ""MySQL"""; StatusMsg: "Sedang menjalankan service MySQL ..."; Flags: runhidden; MinVersion: 0.0,4.0.1381; Tasks: installmysql

;mendaftarkan port default mysql (3306) ke firewall
Filename: "{sys}\netsh.exe"; Parameters: "firewall add portopening TCP 3306 ""Port MySQL"""; StatusMsg: "Sedang mendaftarkan port MySQL ..."; Flags: runhidden; MinVersion: 0,5.01.2600sp2
Filename: "{sys}\netsh.exe"; Parameters: "firewall set service type = fileandprint mode = enable"; StatusMsg: "Mengaktifkan File and Printer Sharing ..."; Flags: runhidden; MinVersion: 0,5.01.2600sp2

;mengganti password default root (blank). ex : masterkey
Filename: "{app}\mysql\bin\mysqladmin.exe"; Parameters: "-uroot password masterkey"; StatusMsg: "Mengganti password root"; Flags: runhidden; MinVersion: 0,5.01.2600sp2

;menghapus user default1 (user=blank, password=blank)
Filename: "{app}\mysql\bin\mysql.exe"; Parameters: "-uroot -pmasterkey -e ""DELETE FROM mysql.user WHERE Host='localhost' AND User=''"""; Flags: runhidden; MinVersion: 0,5.01.2600sp2
Filename: "{app}\mysql\bin\mysql.exe"; Parameters: "-uroot -pmasterkey -e ""FLUSH PRIVILEGES"""; Flags: runhidden; MinVersion: 0,5.01.2600sp2

;menghapus user default2 (user=root, password=blank)
Filename: "{app}\mysql\bin\mysql.exe"; Parameters: "-uroot -pmasterkey -e ""DELETE FROM mysql.user WHERE Host='127.0.0.1' AND User='root'"""; Flags: runhidden; MinVersion: 0,5.01.2600sp2
Filename: "{app}\mysql\bin\mysql.exe"; Parameters: "-uroot -pmasterkey -e ""FLUSH PRIVILEGES"""; Flags: runhidden; MinVersion: 0,5.01.2600sp2

;set agar user root bisa login dari mesin lain (kalo diperlukan)
Filename: "{app}\mysql\bin\mysql.exe"; Parameters: "-uroot -pmasterkey -e ""GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'masterkey'"""; Flags: runhidden; MinVersion: 0,5.01.2600sp2
Filename: "{app}\mysql\bin\mysql.exe"; Parameters: "-uroot -pmasterkey -e ""FLUSH PRIVILEGES"""; Flags: runhidden; MinVersion: 0,5.01.2600sp2

;membuat database kosong
Filename: "{app}\mysql\bin\mysql.exe"; Parameters: "-uroot -pmasterkey -e ""CREATE DATABASE albasi"""; Flags: runhidden; MinVersion: 0,5.01.2600sp2

;menjalankan file batch exec.cmd untuk melakukan proses undump
Filename: "{app}\mysql\bin\exec.cmd"; Flags: runhidden; MinVersion: 0,5.01.2600sp2

;install driver myodbc
Filename: "{sys}\myodbc-installer.exe"; Parameters: "-d -a -n ""MySQL ODBC 5.1 Driver"" -t ""DRIVER=myodbc5.dll;SETUP=myodbc5S.dll"""; StatusMsg: "Tunggu sedang mendaftarkan driver MySQL Connector ODBC 5.1.5"; Flags: runhidden

[UninstallRun]
Filename: {sys}\net.exe; Parameters: "stop ""MySQL"""; StatusMsg: "Menghentikan Service MySQL ..."; Flags: runhidden; MinVersion: 0.0,4.0.1381
Filename: "{app}\mysql\bin\mysqld.exe"; Parameters: "remove ""MySQL"""; StatusMsg: "Sedang menghapus service MySQL ..."; Flags: runhidden; MinVersion: 0,5.01.2600sp2

Filename: "{sys}\myodbc-installer.exe"; Parameters: "-d -r -n ""MySQL ODBC 5.1 Driver"""; StatusMsg: "Tunggu sedang menghapus driver MySQL Connector ODBC 5.1.5"; Flags: runhidden

[UninstallDelete]
Type: files; Name: {app}\mysql\bin\*.*
Type: files; Name: {app}\mysql\Docs\*.*
Type: files; Name: {app}\mysql\lib\*.*
Type: files; Name: {app}\mysql\share\*.*

Type: files; Name: {sys}\myodbc5S.dll
Type: files; Name: {sys}\myodbc5S.lib
Type: files; Name: {sys}\myodbc5.dll
Type: files; Name: {sys}\myodbc5.lib
Type: files; Name: {sys}\myodbc-installer.exe

[Registry]
;mencatat lokasi instalasi program, ini dibutuhkan jika kita ingin membuat paket instalasi update
Root: HKCU; Subkey: "Software\PT ALBASI\SPBB"; ValueName: "installDir"; ValueType: String; ValueData: {app}; Flags: uninsdeletevalue

Di dalam skrip instalasi ada file exec.cmd, isinya adalah :

1
mysql -uroot -pmasterkey albasi < albasi.sql

Isi file exec.cmd sebenarnya untuk proses undump, tapi saya masih belum tau kenapa inno setup gagal menjalankannya padahal perintah-perintah yang lainnya sukses.

Contoh hasil instalasi :

Yuph mungkin itu saja, selamat mencoba :)

Comments