0

VB.net 程序(Visual Studio 2010),您单击按钮并在文本框中获取 cmd 结果现在我有 ipconfig 等基本功能工作,但我无法让自定义命令工作。

我想从用户输入命令textbox2并针对 cmd 运行它并保存输出d:\custwork.kvm12然后读入texbox1但由于某种原因我无法让它工作这是我的代码

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles arptimer.Tick

        Dim p As New System.Diagnostics.ProcessStartInfo("cmd.exe",
                                                         "/C arp -a -v > d:\arpwork.kvm13")
        p.WindowStyle = ProcessWindowStyle.Hidden
        p.CreateNoWindow = True
        Process.Start(p)


        Dim FILE_NAME As String = "d:\arpwork.kvm13"
        Dim Line As String
        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objReader As New System.IO.StreamReader(FILE_NAME)
            Do While objReader.Peek() <> -1
                Line = Line & objReader.ReadLine() & vbNewLine
            Loop
            TextBox1.Text = Line
        Else
            MsgBox("File Does Not Exist")
        End If
        arptimer.Enabled = False

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        arptimer.Enabled = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        iptimer.Enabled = True
    End Sub

    Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iptimer.Tick
        Dim p As New System.Diagnostics.ProcessStartInfo("cmd.exe",
                                                         "/C ipconfig /all> d:\ipwork.kvm12")
        p.WindowStyle = ProcessWindowStyle.Hidden
        p.CreateNoWindow = True
        Process.Start(p)


        Dim FILE_NAME As String = "d:\ipwork.kvm12"
        Dim Line As String
        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objReader As New System.IO.StreamReader(FILE_NAME)
            Do While objReader.Peek() <> -1
                Line = Line & objReader.ReadLine() & vbNewLine
            Loop
            TextBox1.Text = Line
        Else
            MsgBox("File Does Not Exist")
        End If
        iptimer.Enabled = False
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub Timer1_Tick_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles custimer.Tick
        Dim custom As String

        custom = TextBox2.Text + "> d:\custwork.kvm12"

        Dim p As New System.Diagnostics.ProcessStartInfo("cmd.exe")
        p.Arguments = custom
        p.WindowStyle = ProcessWindowStyle.Hidden
        p.CreateNoWindow = false
        Process.Start(p)


        Dim FILE_NAME1 As String = "d:\custwork.kvm12"
        Dim Line1 As String
        If System.IO.File.Exists(FILE_NAME1) = True Then
            Dim objReader As New System.IO.StreamReader(FILE_NAME1)
            Do While objReader.Peek() <> -1
                Line1 = Line1 & objReader.ReadLine() & vbNewLine
            Loop
            TextBox1.Text = Line1
        Else
            MsgBox("File Does Not Exist")
        End If
        custimer.Enabled = False
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        custimer.Enabled = True
    End Sub
End Class
4

0 回答 0