Imports System.IO Public Class SYS_UPDATE ReadOnly ds2 As New DataSet Dim Str As String = Application.StartupPath Private Sub SYS_UPDATE_Load(sender As Object, e As EventArgs) Handles MyBase.Load 資料數 = 6 MyModule1.進度條() : Target = "https://gcm-smart.com/ERP/YD-ERP/" End Sub Private Sub SYS_UPDATE_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown MyModule1.進度條() : Delay(30000) MyModule1.進度條() : Dim Str As String = Application.StartupPath Timer1.Enabled = True End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick Dim 已開啟 As Boolean = False Dim Strs As String = Application.StartupPath If File.Exists(My.Computer.FileSystem.SpecialDirectories.Desktop & "\YD-ERP-SYS.exe") Then Dim pro() As Process = System.Diagnostics.Process.GetProcesses() ' 判斷是否有符合的Process For Each process As Process In pro If ("YD-ERP-SYS").Equals(process.ProcessName) Then 已開啟 = True End If Next If 已開啟 = False Then Timer1.Enabled = False MyModule1.進度條() : If File.Exists(Str + "\YD-ERP-SYS.exe") Then : File.Delete(Str + "\YD-ERP-SYS.exe") : End If MyModule1.進度條() : My.Computer.Network.DownloadFile(Target & "YD-ERP-SYS.exe", Str + "\YD-ERP-SYS.exe") MyModule1.進度條() : Shell(Str + "\YD-ERP-SYS.exe", vbNormalFocus) Me.Close() End If ElseIf File.Exists(Strs & "\YD-ERP-SYS.exe") Then Dim pro() As Process = System.Diagnostics.Process.GetProcesses() ' 判斷是否有符合的Process For Each process As Process In pro If ("YD-ERP-SYS").Equals(process.ProcessName) Then 已開啟 = True End If Next If 已開啟 = False Then Timer1.Enabled = False MyModule1.進度條() : If File.Exists(Str + "\YD-ERP-SYS.exe") Then : File.Delete(Str + "\YD-ERP-SYS.exe") : End If MyModule1.進度條() : My.Computer.Network.DownloadFile(Target & "/" & "YD-ERP-SYS.exe", Str + "\YD-ERP-SYS.exe") MyModule1.進度條() : Shell(Str + "\YD-ERP-SYS.exe", vbNormalFocus) Me.Close() End If End If End Sub Public Sub Delay(ByRef Interval As Double) 'Interval单位为毫秒 Dim time As DateTime = DateTime.Now Dim Span As Double = Interval * 1234 While ((DateTime.Now.Ticks - time.Ticks) < Span) Application.DoEvents() End While End Sub End Class