Hello dearest community,
我正在尝试使用VB.NET构建一个简单的AutoUpdate应用程序。这很简单。也就是说,我将最新的ZIP文件放在我的托管网站中,然后使用WebClient.DownloadFileAsync
下载它。下载后,我使用http://stahlforce.com/dev/unzip.exe
但是每次使用unzip.exe
运行Process.start
时,Windows 7都会显示Open File Security。
VB.NET是否可以绕过此类安全限制?
感谢。
顺便说一句,这是我使用WebClient.DownloadFileAsync
的代码,以防任何人谷歌关于它并登陆此页面:
Public Class AutoUpdate
Dim installationFolder As String = "C:\Program Files\xyz\abc\"
Dim updateFileNameTarget As String
Private Sub btnStartUpdte_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartUpdte.Click
lblPercent.Text = ""
lblDownloading.Text = ""
lblDownloading.Text = ""
pbDownloadStatus.Value = 0
Dim wc As New WebClient
AddHandler wc.DownloadFileCompleted, AddressOf downloadComplete
AddHandler wc.DownloadProgressChanged, AddressOf progressChanged
Dim path As String = "http://xyz.abc.com/test.zip"
updateFileNameTarget = installationFolder & "test.zip"
Try
If File.Exists(updateFileNameTarget) Then
File.Delete(updateFileNameTarget)
End If
lblDownloading.Text = "Downloading " & path
wc.DownloadFileAsync(New Uri(path), updateFileNameTarget)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub progressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
pbDownloadStatus.Value = e.ProgressPercentage
lblPercent.Text = e.ProgressPercentage & "%"
End Sub
Private Sub downloadComplete(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
MessageBox.Show("Download complete. Now extracting")
Dim cmd As String = Application.StartupPath & "\Tools\unzip.exe"
Dim arg As String = "-o """ & updateFileNameTarget & """"
Process.Start(cmd, arg)
End Sub
End Class
答案 0 :(得分:1)
如果您已经在进程中调用其他所有内容(包括解压缩),请使用Sysinternal's streams.exe。使用-d
标志删除NTFS备用数据流(ADS)。应该只有一个 - 它是向Windows指示该文件是从“不受信任的来源”下载的。
您下载的文件目前有一个如下所示的流:
:Zone.Identifier:$DATA 26
在解压缩之后但在执行之前从下载文件中删除此流,并且不再显示警告。
另请参阅:What is Zone Identifier? - 和Accessing alternate data streams in files,以便在.NET中使用这些库而无需streams.exe
。