如何使用VB.Net在特定目录中打开命令提示符

时间:2018-02-04 20:00:42

标签: vb.net command-line notepad++ command-prompt

我需要以编程方式打开命令提示符,但在特定目录中打开它。

在Notepad ++中,有一个选项可以在命令提示符下打开文件的目录。

Here is what it looks like in Notepad++.

你会怎么做?

1 个答案:

答案 0 :(得分:1)

你需要这样的东西:

Const WorkingDirectory As String = "E:\Shared" ' the directory you want to be on
Dim exePath As String = Environment.SystemDirectory & "\cmd.exe"
Dim StartInfo As New ProcessStartInfo(exePath)
Dim cmdSession As New Process

StartInfo.UseShellExecute = False
StartInfo.WorkingDirectory = WorkingDirectory ' start in this directory
StartInfo.Arguments = "/k" ' let cmd.exe remain running using /k
cmdSession.StartInfo = StartInfo

cmdSession.Start()

问候,保罗