如何执行多个命令以在使用命令行在单个进程中打开cmd.exe的Process.Start()中打开应用程序?

时间:2018-07-10 11:54:50

标签: vb.net command-line cmd process

我无法在单次执行中将目录从C:\更改为C:\Apps\app.exe。 Cmd不允许我这样做。我想先执行C:\Apps,然后执行app.exe参数以便使用app.exe打开Process.Start()并在一次运行中打开cmd.exe。这是我的代码。

Dim FullPath As String = "C:\Apps\app.exe"
Dim appPath As String = "C:\Apps"
Dim appName As String = "app.exe"
Dim p As Process = Process.Start("cmd.exe", "/k cd " + appPath)
'Don't know what to do here...

我的输出应该是这样的:
Cmd

1 个答案:

答案 0 :(得分:0)

由于@Babbillumpa,我已经解决了我的问题:

Dim _processStartInfo As ProcessStartInfo = New ProcessStartInfo()
        _processStartInfo.WorkingDirectory = appPath
        _processStartInfo.FileName = "cmd.exe"
        _processStartInfo.Arguments = "/k app.exe"
        _processStartInfo.CreateNoWindow = True

        Dim myProcess As Process = Process.Start(_processStartInfo)
        'wait for specific time for the thread to be closed
        myProcess.WaitForExit(500)

        ' Close process by sending a close message to its main window.
        myProcess.CloseMainWindow()
        ' Free resources associated with process.
        myProcess.Close()