我试图从一个VB.NET应用程序内运行目标相对路径。我已经确保使用反斜杠(而不是正斜杠),并且还要将工作目录设置为正确的源路径来运行Process;尝试运行时仍出现The system cannot find the file specified
错误。在Windows中运行相对路径?
例如,我有(伪代码):
txtSource.text path = "C:\Windows\System32"
txtResult.text path = "..\notepad.exe"
这里的小组到目前为止:
Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
Try
' Create the process object
Dim pRun As New Process()
' Set it to run from the Source folder (Working Directory)
With pRun.StartInfo
.UseShellExecute = False
.WorkingDirectory = IO.Path.GetDirectoryName(txtSource.Text.Trim)
.FileName = txtResult.Text.Trim
End With
pRun.Start()
' Wait for it to finish
pRun.WaitForExit()
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End Sub
两点('..')表示一个目录级别比当前更高。一个点('.')表示当前目录。 – TnTinMn
在此示例中,C:\ Windows \ notepad.exe是比C:\ Windows \ System32更高的一个目录级别。 –