我一直在编写一些 vb.net 2010 编码,但我被困在一段代码上,我不知道如何修复它,所以这就是为什么我请求你帮助我处理这段代码。
代码:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim url As New System.Uri("http://example/one/")
Dim req As System.Net.WebRequest
req = System.Net.WebRequest.Create(url)
Dim resp As System.Net.WebResponse
Dim filePath As String
filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\examplepath"
Try
resp = req.GetResponse()
resp.Close()
req = Nothing
Process.Start("filePath\Test.exe")
Catch ex As Exception
req = Nothing
Me.Close()
End Try
End Sub
问题: %APPDATA%\ExamplePath\Test.bat 中的文件无法打开。
希望你能帮助我:)
最佳答案
这行似乎有问题:
Process.Start("filePath\Test.exe")
这里你把一个变量作为字符串,这当然是行不通的。相反,将其与文件名连接起来:
Process.Start(filePath & "\Test.exe")
这可行,但处理文件系统的更好方法是使用 Path
类和 Combine
方法来处理具有多个部分的路径:
Process.Start(Path.Combine(filePath, "Test.exe"))
这涉及放置正确的分隔符以及它可能有也可能没有尾部反斜杠的事实。
关于VB.NET 2010 - Process.Start ("filePath\Test.bat")未打开 test.bat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43170589/