ส่วนของผมติดตั้ง MySQL ครับ ผมใช้ bat ไฟล์รันคำสั่งติดตั้งและคอนฟิกโปรแกรม
โดยในไฟล์ติดตั้งก็บรรจุ ตัวติดตั้งไว้
เมื่อเขียนไฟล์จาก My.Resources ของโปรแกรมไปไว้ที่ temp โฟล์เดอร์
จากนั้นก็สั่งให้ VB เขียนไฟล์ bat ขึ้นมา แล้วก็ รันไฟล์ bat เพื่อติดตั้งฐานข้อมูล
ติดตั้งเสร็จก็คอนฟิก คอนฟิกเสร็จก็ รีสตาร์ทฐานข้อมูลใหม่และสั่ง ดรัมข้อมูลเข้า (ทั้งหมดเสร็จในไฟล์ bat อันเดียว)
เผื่อเป็นแนวทาง ลองประยุกต์ใช้ดูนะครับ
Code (VB.NET)
'write mysql to disk
Dim temMariaDBPath As String = temp & "mysql_5_5_54_win32.msi"
Call LoadResourceToDisk(My.Resources.mysql_5_5_54_win32, temMariaDBPath)
System.IO.File.SetAttributes(temMariaDBPath, IO.FileAttributes.Hidden)
Dim mysqlfile As String = temp & "bak4_3.sql"
System.IO.File.WriteAllText(mysqlfile, My.Resources.bak4_3)
System.IO.File.SetAttributes(mysqlfile, IO.FileAttributes.Hidden)
Dim sb As New System.Text.StringBuilder
sb.AppendLine("@echo off")
sb.AppendLine("echo ==========Install Application Developer By P A Tech Group ========== ")
sb.AppendLine("echo Install MySQL...")
sb.AppendLine("msiexec /i """ & temMariaDBPath & """ /passive")
sb.AppendLine("echo Config MySQL...")
sb.AppendLine("cd ""C:\Program Files\MySQL\MySQL Server 5.5\bin\""")
sb.AppendLine("mysqlinstanceconfig.exe -i -q ServiceName=ServicetickerDB RootPassword=1234 ServerType=DEVELOPER DatabaseType=INODB Port=3306 Charset=utf8")
sb.AppendLine("mysql -uroot -p1234 -e ""GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '1234' WITH GRANT OPTION; FLUSH PRIVILEGES;")
sb.AppendLine("mysqladmin -uroot -pFx1rpB CREATE serviceticker")
sb.AppendLine("echo Install MySQL Done.")
sb.AppendLine("exit")
IO.File.WriteAllText(temp & "sti.bat", sb.ToString())
System.IO.File.SetAttributes(temp & "sti.bat", IO.FileAttributes.Hidden)
If osVer.Major < 6 Then
Thread.Sleep(5000)
Try
Dim runbat As Process = Process.Start(temp & "sti.bat")
runbat.WaitForExit()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Thread.Sleep(5000)
ElseIf osVer.Major >= 6 Then
Try
Dim procInfo As New ProcessStartInfo()
procInfo.UseShellExecute = True
procInfo.FileName = (temp & "sti.bat")
procInfo.WorkingDirectory = ""
procInfo.Verb = "runas"
Dim runbat As Process = Process.Start(procInfo)
runbat.WaitForExit()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End If
'write my.ini
writeIni(FileConfigINI_mcode, "client", "default-character-set", "utf8")
writeIni(FileConfigINI_mcode, "mysqld", "max_allowed_packet", "102400M")
writeIni(FileConfigINI_mcode, "mysqld", "socket", "/tmp/mysql.sock")
writeIni(FileConfigINI_mcode, "client", "socket", "/tmp/mysql.sock")
writeIni(FileConfigINI_mcode, "mysqld", "max_connections", "1500")
Dim mysqlfile1 As String = temp & "bak4_3.sql"
'Stop MySQL
Dim stopmysql As New System.Text.StringBuilder
stopmysql.AppendLine("@echo off")
stopmysql.AppendLine("echo ========== Restart MySQL :: Developer By P A Tech Group ========== ")
stopmysql.AppendLine("net stop ServicetickerDB")
stopmysql.AppendLine("net start ServicetickerDB")
'Dump Mysql
stopmysql.AppendLine("@echo off")
stopmysql.AppendLine("echo ========== Dump Database :: Developer By P A Tech Group ========== ")
stopmysql.AppendLine("cd ""C:\Program Files\MySQL\MySQL Server 5.5\bin\""")
stopmysql.AppendLine("mysql -uroot -p1234 --default-character-set=utf8 serviceticker < """ & mysqlfile1 & """")
stopmysql.AppendLine("exit")
IO.File.WriteAllText(temp & "stdump.bat", stopmysql.ToString())
System.IO.File.SetAttributes(temp & "stdump.bat", IO.FileAttributes.Hidden)
'write serviceticker to disk
Dim temmyst2Path As String = temp & "setup_serviceticker.exe"
Call LoadResourceToDisk(My.Resources.Setup_ServiceTicker2_0_1_44, temmyst2Path)
'Install Crysal Report RunTime x64
Dim temCrystalPath As String = temp & "CRRuntime_64bit_13_0_18.msi"
Call LoadResourceToDisk(My.Resources.CRRuntime_64bit_13_0_18, temCrystalPath)
Dim sb As New System.Text.StringBuilder
sb.AppendLine("@echo off")
sb.AppendLine("echo Install Crystal Report...")
sb.AppendLine("msiexec /i """ & temCrystalPath & """ /passive")
sb.AppendLine("echo Done.")
sb.AppendLine("exit")
IO.File.WriteAllText(temp & "sti.bat", sb.ToString())
If osVer.Major < 6 Then
Try
Dim runbat As Process = Process.Start(temp & "sti.bat")
runbat.WaitForExit()
Catch ex As Exception
MsgBox(ex.Message)
End Try
ElseIf osVer.Major >= 6 Then
Try
Dim procInfo As New ProcessStartInfo()
procInfo.UseShellExecute = True
procInfo.FileName = (temp & "sti.bat")
procInfo.WorkingDirectory = ""
procInfo.Verb = "runas"
Dim runbat As Process = Process.Start(procInfo)
runbat.WaitForExit()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If