VB.Net SpecialFolder.ApplicationData不能正常工作

时间:2017-03-13 16:38:05

标签: vb.net settings auto-update

我正在处理您可以启用和禁用的更新检查程序设置。 如果启用设置,将创建一个名为“UA.set”的文件 现在我将更新检查消息与一个代码相结合,该代码将检查文件UA.set文件是否存在,但我不工作... 你可以帮我解决这个问题吗?

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim filePath As String
    filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\MozarCodes\DuckyTool2\Settings"
    Dim objFSO, strFile
    strFile = "filePath\UA.set"
    objFSO = CreateObject("Scripting.FileSystemObject")
    If Not objFSO.FileExists(strFile) Then
        Dim url As New System.Uri("http://mozarcodes.netne.net/DT2-1/")
        Dim req As System.Net.WebRequest
        req = System.Net.WebRequest.Create(url)
        Dim resp As System.Net.WebResponse
        Try
            resp = req.GetResponse()
            resp.Close()
            req = Nothing
            MsgBox("Update Found! Please update to our latest version on http://mozarcodes.netne.net/")
        Catch ex As Exception
            req = Nothing
            MsgBox("You are now using the latest version of DuckyTool 2!")
        End Try
    End If
    Threading.Thread.Sleep("1")
End Sub

非常感谢! (如果找到解决方案,我会在我的网站上给予积分:D)

1 个答案:

答案 0 :(得分:1)

您正在使用此行测试不存在的文件

strFile = "filePath\UA.set"

正确的代码应该是

filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\MozarCodes\DuckyTool2\Settings"
Dim objFSO, strFile
strFile = filePath & "\UA.set"

顺便说一句,请丢弃旧的VB6 / VBA对象,如Scripting.FileSystemObject,并使用.NET Framework的类和方法

If Not File.Exists(strFile) Then