【发布时间】:2016-06-03 21:04:48
【问题描述】:
我已将代码设置为使用Form1_Load 在运行时执行,该代码是一个简单的程序集检查,以查看版本是否低于通过 Webclient 获得的服务器上保存的版本。如果它较低,它会从那里下载最新的 EXE 并使用 CMD 重命名它并用旧的 .exe 替换它(在应用程序打开时它以某种方式工作)
问题:
它使虚假反病毒检测认为它试图感染其他应用程序(Trojan Dropper Variant)
在某些情况下无效(例如:用户第一次下载应用程序并将其重命名为默认 EXE 名称以外的其他名称,然后就无法正常工作)
CMD 甚至可能无法在某些机器上运行,例如 School PC 的 e.t.c
一般来说,使用 CMD 并不是一个好主意。
我不想做的解决方案:
使用第二个 .exe,其唯一目的是更新应用程序;
CMD 废话
至少尽量不要使用来自 .dll 的 Nuget 包/外部引用
不是仅当用户在 MessageBox e.t.c 上按 Yes/OK 时才更新的代码
那么我该如何解决这个不得不使用 CMD 的问题呢?
我当前的代码:
#Region "Update Checker"
#Region "Test Internet Connection"
'Ping Google to see if the user has Internet Connected;
Private Function TestInternetConnection() As Boolean
Try
Dim ping As New Net.NetworkInformation.Ping()
ping.Send("google.com")
Return True
Catch ex As Exception
Return False
End Try
End Function
#End Region
#Region "Check for an Update"
Private Sub CheckForUpdate()
'If the user is Connected to the Internet;
If TestInternetConnection() Then
Try
'Using WebClient, get the Newest File Version;
Using wc As New WebClient
'Latest Version;
Dim LatestVersion As String = wc.DownloadString("http://proxyfuel.xyz/version.txt")
'If the Latest Version is Newer then the Current Version;
If LatestVersion > Application.ProductVersion Then
'Download the Latest Version of the EXE file;
wc.DownloadFile("{Application EXE Direct Link}", Application.StartupPath & "\update.exe")
'Execute the CMD Batch File to replace the old EXE file with the Newest EXE file;
Process.Start(New ProcessStartInfo("cmd.exe", String.Format("/k {0} & {1} & {2} & {3}", "ping -n 3 127.0.0.1 > NUL", "del ""ProxyFuel.exe""", "REN ""update.exe"" ""ProxyFuel.exe""", "start """" ""ProxyFuel.exe""")).WindowStyle = ProcessWindowStyle.Hidden)
'Close the Application;
Application.Exit()
Else
'Start Loading the Main Form;
My.Settings.updatechecked = True
End If
End Using
Catch ex As Exception
'Updating had an Unexpected Error;
MessageBox.Show(ex, "Update Error!", MsgBoxStyle.Critical)
End Try
Else
'No Internet Connection - Couldnt connect to the Data Server;
MessageBox.Show("Internet Connection Required!", "Error")
End If
End Sub
#End Region
#End Region
【问题讨论】:
-
(Somehow it works while the application is open)不可能。也许它正在默默地失败。 -
@Plutonix 这是一种可能性,但因为它实际上并没有加载显示表单并在打开应用程序的同时关闭应用程序可能不是
标签: .net vb.net windows visual-studio cmd