ボタンをクリックして cmd の結果をテキスト ボックスに表示する VB.net プログラム (Visual Studio 2010) で、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