【发布时间】:2016-02-07 08:47:45
【问题描述】:
通过我的表单,我打开了一个位于 debug 文件夹中的 .exe:
\bin\Debug\文件夹\.exe
.exe 打开并创建 3 个不同的文件,然后关闭。它的目的是在与 .exe 相同的文件夹中创建它们,而是在使用 Process.Start() 通过 VB.net 打开时在 Debug 文件夹中创建它们。
有没有人可以解决这个问题,这样我就不必移动文件了?
编辑 (.exe 本身创建文件,有些东西可能在这个子之外声明)
Private Sub btnRunExe_Click(sender As Object, e As EventArgs) Handles btnRunExe.Click
If AcptEULA.Checked = True Then
Localpath = Application.StartupPath() + "\MCserver" + "\minecraft_server." + txtVersion.Text + ".exe"
Downloadpath = "https://s3.amazonaws.com/Minecraft.Download/versions/" + txtVersion.Text + "/minecraft_server." + txtVersion.Text + ".exe"
LocalpathParent = Application.StartupPath() + "\MCserver"
Try
Dim dirs As String() = Directory.GetFiles(LocalpathParent, "minecraft_server*.exe")
Dim dir As String
For Each dir In dirs
Process.Start(dir)
Next
Catch
'Console.WriteLine("The process failed: {0}", e.ToString())
End Try
ElseIf AcptEULA.Checked = False Then
MsgBox("You must accept the Minecraft EULA before continuing")
End If
End Sub
【问题讨论】:
-
1. 不要硬编码路径。 2. 向我们展示您的代码!
-
BIN\DEBUG 文件夹是您的程序在调试时运行的默认文件夹。这对 Visual Studio 会话之外的程序的实际执行没有影响。请显示打开exe的代码。
-
@Steve :在我看来问题在于他对路径进行了硬编码。
-
@VisualVincent 只有代码知道!