-2

我在 VB.NET 中开发了一个应用程序...

 Dim DIAGTOOL_loc As String = Environment.CurrentDirectory & "\folder\file.exe"
 Dim shellexec As New System.Text.StringBuilder
 shellexec.AppendLine("@echo off")
 shellexec.AppendLine("cls()")
 shellexec.AppendLine(": begin()")
 shellexec.AppendLine("cls()")  
 shellexec.AppendLine("START " & DIAGTOOL_loc.ToString)
 shellexec.AppendLine("pause")
 IO.File.WriteAllText("tester.bat", shellexec.ToString())

 System.Diagnostics.Process.Start("tester.bat")

现在,当命令提示符打开时,它应该执行 file.exe (DIAGTOOL_loc),但是当 CMD 加载时,它说“Windows 找不到“C:\Users\ ...”

但为什么?怎么了?当我键入 Process.start(DIAGTOOL_loc) 时,在 DIAGTOOL_loc 变量中注册的路径有效,因此,该文件存在......为什么 cmd 找不到它?

这个命令:

shellexec.AppendLine("START " & DIAGTOOL_loc.ToString)

应该打开file.exe ...但它不起作用...

4

2 回答 2

0

尝试这个:

shellexec.AppendLine(String.Format("START """{0}""" , DIAGTOOL_loc)) 

还修复您的批处理命令:

 shellexec.AppendLine("cls")   
 shellexec.AppendLine(":begin")   
 shellexec.AppendLine("cls")  
于 2012-08-16T09:54:09.830 回答
0

在您生成的文件tester.bat中,您将看到如下所示的一行:

START c:\users\some folders\folder\file.exe

正如你所看到的,路径没有被引用,所以如果路径包含空格(我怀疑你的),这将失败。

请注意,您的代码也可以更好地编写 - 使用System.IO.Path.Combine组合路径的各个部分:

 Dim DIAGTOOL_loc As String = _
     """ + Path.Combine(Environment.CurrentDirectory, "\folder\file.exe") + """
于 2012-08-16T09:54:31.513 回答