Imports System.Net
Public Class Form1
Dim WithEvents WC As New WebClient
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WC.DownloadFileAsync(New Uri("http://127.0.0.1/filedownload/setup.exe"), "setup.exe")
End Sub
Private Sub WC_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles WC.DownloadProgressChanged
ProgressBar1.Value = e.ProgressPercentage
Label1.Text = e.ProgressPercentage & " %"
Label2.Text = "กำลังดาวน์โหลดไฟล์...."
End Sub
Private Sub WC_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WC.DownloadFileCompleted
Dim p As Process = Process.Start(My.Application.Info.DirectoryPath & "\setup.exe")
Label2.Text = "กำลังติดตั้ง...."
p.WaitForExit()
My.Computer.FileSystem.DeleteFile(My.Application.Info.DirectoryPath & "\setup.exe")
Label2.Text = "ติดตั้งไฟล์เสร็จสิ้น..."
End Sub
End Class
Imports System.Net
Public Class Form1
Dim WithEvents WC As New WebClient
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WC.DownloadFileAsync(New Uri("http://127.0.0.1/filedownload/setup.exe"), "setup.exe")
End Sub
Private Sub WC_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles WC.DownloadProgressChanged
ProgressBar1.Value = e.ProgressPercentage
Label1.Text = e.ProgressPercentage & " %"
Label2.Text = "กำลังดาวน์โหลดไฟล์...."
End Sub
Private Sub WC_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WC.DownloadFileCompleted
Dim p As Process = Process.Start(My.Application.Info.DirectoryPath & "\setup.exe")
Label2.Text = "กำลังติดตั้ง...."
p.WaitForExit()
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
My.Computer.FileSystem.DeleteFile(My.Application.Info.DirectoryPath & "\setup.exe")
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar2.Value = e.ProgressPercentage
Label4.Text = e.ProgressPercentage & " %"
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
Label2.Text = "ติดตั้งไฟล์เสร็จสิ้น..."
End Sub
End Class