vb.net的windows窗体实现dos命令__教程 |
|
日期:2007-5-20 1:23:26 人气:82 [大 中 小] |
|
|
|
Me.tbComText.TabIndex = 5 Me.tbComText.Text = "Dir" ' 'btClear ' Me.btClear.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.btClear.Location = New System.Drawing.Point(40, 8) Me.btClear.Name = "btClear" Me.btClear.Size = New System.Drawing.Size(80, 24) Me.btClear.TabIndex = 3 Me.btClear.Text = "清空(&C)" ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(160, 8) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(48, 16) Me.Label1.TabIndex = 2 Me.Label1.Text = "命令:" ' 'btnExcute ' Me.btnExcute.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.btnExcute.Location = New System.Drawing.Point(472, 8) Me.btnExcute.Name = "btnExcute" Me.btnExcute.Size = New System.Drawing.Size(80, 24) Me.btnExcute.TabIndex = 1 Me.btnExcute.Text = "执行(&E)" ' 'frmCmdExcute ' Me.AcceptButton = Me.btnExcute Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) Me.ClientSize = New System.Drawing.Size(600, 365) Me.Controls.Add(Me.Panel1) Me.Controls.Add(Me.tbResult) Me.Name = "frmCmdExcute" Me.Text = "Command Excute Result" Me.Panel1.ResumeLayout(False) Me.ResumeLayout(False)
End Sub
#End Region
Public Shared Sub Main() If System.Environment.OSVersion.ToString.IndexOf("NT") = -1 Then MsgBox("暂时不支持非NT系统,程序退出!") Application.Exit() Else Application.Run(New frmCmdExcute) End If End Sub
Private Delegate Sub TextAddHandler(ByVal strPara As String)
#Region "private viable" Dim sw As IO.StreamWriter Dim sr As New MyStreamReader Dim err As New MyStreamReader Dim p As System.Diagnostics.Process = New System.Diagnostics.Process Dim psI As New System.Diagnostics.ProcessStartInfo(System.Environment.GetEnvironmentVariable("ComSpec")) #End Region
Private Sub frmCmdExcute_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load p = New System.Diagnostics.Process '"cmd.exe"为nt的命令行程序 psI = New System.Diagnostics.ProcessStartInfo("cmd.exe") psI.UseShellExecute = False psI.RedirectStandardInput = True psI.RedirectStandardOutput = True psI.RedirectStandardError = True psI.CreateNoWindow = True p.StartInfo = psI
p.Start() sw = p.StandardInput sr.stream = p.StandardOutput err.stream = p.StandardError sw.AutoFlush = True sr.stream.BaseStream.BeginRead(sr.bytes, 0, 1024, New AsyncCallback(AddressOf CBstream), sr) err.stream.BaseStream.BeginRead(err.bytes, 0, 1024, New AsyncCallback(AddressOf CBstream), err) End Sub
Private Sub frmCmdExcute_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed p.Close() If Not sw Is Nothing Then sw.Close() End If If Not sr Is Nothing Then sr.stream.Close() End If If Not err Is Nothing Then |
|
出处:本站原创 作者:佚名 |
|
|