无法获取System.Diagnostics.ProcessStartInfo以从字符串中获取参数

时间:2013-10-04 15:25:49

标签: vb.net winforms

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 在这里工作是我的代码

{{1}}

0 个答案:

没有答案