使用Visual Basic播放CMD中的《星球大战》

时间:2019-03-02 23:14:07

标签: vb.net cmd

我知道我需要运行的2条命令是:

pkgmgr /iu:"TelnetClient"
Telnet Towel.blinkenlights.nl

我希望它在运行Telnet Towel.blinkenlights.nl之后保持cmd打开。

这是我尝试过的:

    Dim start As New Process()
    start.StartInfo.FileName = "cmd.exe"
    start.StartInfo.Arguments = "/c pkgmgr /iu:" & """" & "TelnetClient" & """"
    start.StartInfo.CreateNoWindow = True
    start.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    start.StartInfo.UseShellExecute = False
    start.Start()
    System.WaitForExit()

    Dim playSW As New Process()
    playSW.StartInfo.FileName = "cmd.exe"
    playSW.StartInfo.Arguments = "/k Telnet Towel.blinkenlights.nl"
    playSW.Start()
    playSW.WaitForExit()

2 个答案:

答案 0 :(得分:1)

您可以使用流程的WaitForExit命令来确保流程完成:

Dim start As New Process()
start.StartInfo.FileName = "cmd.exe"
start.StartInfo.Arguments = "/c pkgmgr /iu:" & """" & "TelnetClient" & """"
start.StartInfo.CreateNoWindow = True
start.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
start.StartInfo.UseShellExecute = False
start.Start()
start.WaitForExit()

Dim playSW As New Process()
playSW.StartInfo.FileName = "cmd.exe"
playSW.StartInfo.Arguments = "/c Telnet Towel.blinkenlights.nl"
playSW.Start()
playSW.WaitForExit()

参考:https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.waitforexit?view=netframework-4.7.2

答案 1 :(得分:0)

谢谢您的答复,为了解决我的问题,我安装了32位版本的Putty,并通过将-telnet Towel.blinkenlights.nl传递给它来建立telnet连接。 之所以可行,是因为32位VB程序随后可以打开32位Putty并调用命令。之所以无法正常运行,是因为telnet.exe需要64位程序。