How to run DOS/CMD/Command Prompt commands from VB.NET?

前端 未结 5 860
旧时难觅i
旧时难觅i 2020-12-08 16:38

The question is self-explanatory. It would be great if the code was one line long (something to do with \"Process.Start(\"...\")\"?). I researched the web but o

5条回答
  •  萌比男神i
    2020-12-08 16:59

    Imports System.IO
    Public Class Form1
        Public line, counter As String
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            counter += 1
            If TextBox1.Text = "" Then
                MsgBox("Enter a DNS address to ping")
            Else
                'line = ":start" + vbNewLine
                'line += "ping " + TextBox1.Text
                'MsgBox(line)
                Dim StreamToWrite As StreamWriter
                StreamToWrite = New StreamWriter("C:\Desktop\Ping" + counter + ".bat")
                StreamToWrite.Write(":start" + vbNewLine + _
                                    "Ping -t " + TextBox1.Text)
                StreamToWrite.Close()
                Dim p As New System.Diagnostics.Process()
                p.StartInfo.FileName = "C:\Desktop\Ping" + counter + ".bat"
                p.Start()
            End If
        End Sub
    End Class
    

    This works as well

提交回复
热议问题