Lzmtw
7/24/2004
http://blog.9cbs.net/lzmtw/
interface
Note: The program does not work properly in Windows98.
Public class frmcmdexcute
Inherits System.Windows.Forms.form
Dim SW as system.io.streamwriter
Dim Sr as system.io.streamReader
Dim Err as system.io.streamReader
DIM P as system.diagnostics.process = new system.diagnostics.process
Dim psi as new system.diagnostics.ProcessStartInfo (System.environment.GetenvironmentvironmentVariable ("comspec"))
#Region "Windows Form Designer Generated Code"
Public Sub New ()
Mybase.new ()
'This call is required for the Windows Form Designer.
InitializeComponent ()
'Add any initialization after INITIALIZECOMPONENT ()
End Sub
'Form rewriting Dispose to clean up the list of components.
Protected Overloads Overrides Sub Dispose (Byval Disposing as Boolean)
IF Disposing then
IF not (Components Is Nothing) THEN
Components.dispose ()
END IF
END IF
Mybase.dispose (Disposing)
End Sub
'Windows Form Designer
Private Components as System.comPonentModel.icontainer
'Note: The following process is necessary for the Windows Form Designer.
'You can modify this process using the Windows Form Designer.
'Don't modify it using the code editor.
Friend Withevents TBRESULT As System.Windows.Forms.TextBox
Friend Withevents Panel1 As System.Windows.Forms.Panel
Friend Withevents btnexcute as system.windows.Forms.Button
Friend Withevents Label1 As System.Windows.Forms.Label
Friend Withevents BTCLEAR as System.Windows.Forms.Button
Friend withevents btlocate as system.windows.Forms.Button
Friend Withevents Tbcomtext as system.windows.Forms.comBobox
Me.tbresult = new system.windows.Forms.TextBox
Me.Panel1 = new system.windows.Forms.Panel
Me.Tbcomtext = new system.windows.Forms.comBobox
Me.btlocate = new system.windows.Forms.Button
Me.btclear = new system.windows.Forms.ButtonMe.label1 = new system.windows.Forms.label
Me.btnexcute = new system.windows.Forms.Button
Me.Panel1.suspendlayout ()
Me.suspendlayout ()
'
'TBRESULT
'
Me.tbresult.Anchor = ctype (((System.Windows.Forms.Anchorstyles.top or system.windows.forms.Anchorstyles.bottom) _
OR system.windows.forms.Anchorstyles.left)
Or System.Windows.Forms.Anchorstyles.right, System.Windows.Forms.Anchorstyles
Me.tbresult.backcolor = system.drawing.systemcolors.info
Me.tbresult.Borderstyle = system.windows.Forms.Borderstyle.fixedsingLele
Me.tbresult.location = new system.drawing.point (8, 8)
Me.tbresult.multiline = true
Me.tbresult.name = "TBRESULT"
Me.tbresult.readonly = true
Me.tbresult.scrollbars = system.windows.Forms.Scrollbars.both
Me.tbresult.size = new system.drawing.size (584, 304)
Me.tbresult.tabindex = 0
Me.tbresult.tabstop = false
Me.tbresult.text = ""
'
'Panel1
'
Me.Panel1.anchor = CType ((System.Windows.Forms.Anchorstyles.Bottom or System.Windows.Forms.Anchorstyles.right), System.Windows.Forms.Anchorstyles
Me.Panel1.Controls.add (me.tbcomtext)
Me.Panel1.Controls.add (me.btlocate)
Me.Panel1.Controls.add (me.btclear)
Me.Panel1.controls.add (me.label1)
Me.Panel1.Controls.add (me.btnexcute)
Me.Panel1.Location = new system.drawing.point (8, 320)
Me.Panel1.name = "panel1"
Me.Panel1.size = new system.drawing.size (584, 40)
Me.Panel1.tabindex = 1
'
'TBCOMTEXT
'
Me.Tbcomtext.location = new system.drawing.point (264, 8)
Me.tbcomtext.name = "tbcomtext"
Me.tbcomtext.size = new system.drawing.size (224, 20)
Me.tbcomtext.tabindex = 5me.tbcomtext.text = "DIR"
'
'btlocate
'
Me.btlocate.flatstyle = system.windows.Forms.Flatstyle.FLAT
Me.btlocate.location = new system.drawing.point (96, 8)
Me.btlocate.name = "btlocate"
Me.btlocate.size = new system.drawing.size (80, 24)
Me.btlocate.tabindex = 4
Me.btlocate.text = "Location (& L)"
'
'btclear
'
Me.btclear.flatstyle = system.windows.Forms.Flatstyle.FLAT
Me.btclear.location = new system.drawing.point (8, 8)
Me.btclear.name = "btclear"
Me.btclear.size = new system.drawing.size (80, 24)
Me.btclear.tabindex = 3
Me.btclear.text = "Empty (& C)"
'
'Label1
'
Me.label1.location = new system.drawing.point (208, 8)
Me.Label1.name = "label1"
Me.label1.size = new system.drawing.size (48, 16)
Me.label1.tabindex = 2
Me.Label1.Text = "command:"
'
'btnexcute
'
Me.btnexcute.enabled = false
Me.btnexcute.flatstyle = system.windows.Forms.Flatstyle.FLAT
Me.btnexcute.location = new system.drawing.point (496, 8)
Me.btnexcute.name = "btnexcute"
Me.btnexcute.size = new system.drawing.size (80, 24)
Me.btnexcute.tabindex = 1
Me.btnexcute.text = "Execute (& 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
Private sub btclear_click (byval sender as system.object, byval e as system.eventargs) handles btclear.clickme.tbresult.text = string.empty
End Sub
Private sub btlocate_click (Byval e as system.EventArgs) Handles BTLOCATE.CLICK
DIM BD AS New FolderbrowserDialog
If bd.showdialog = DialogResult.ok then
System.environment.currentdirectory = bd.selectedPath
END IF
End Sub
Private sub TBCOMTEXT_KEYUP (Byval e as system.windows.forms.keyeventargs) Handles TBCOMTEXT.KEYUP
If E.keyData = Keys.enter Then
DIM cmd as string = me.tbcomtext.text.tolower
If cmd.equals (string.empty) THEN CMD = "DIR"
Me.cursor = system.windows.Forms.cursors.Waitcursor
SW.WRITELINE (CMD)
Me.tbresult.text = sr.readToeD ()
Me.tbresult.text = Err.ReadToend ()
Me.cursor = system.windows.forms.cursors.default
DIM CURRENT AS STRING = String.empty
IF cmd.startswith ("cd /") or cmd.startswith ("cd") THEN
CURRENT = cmd.substring (3)
END IF
IF cmd.endswith (":") THEN
Current = cmd
END IF
IF not current.equals (string.empty) THEN
If io.directory.exists (current) THEN
System.environment.currentDirectory = currentdiRectory = CURRENT
END IF
END IF
Me.tbcomtext.Items.add (me.tbcomtext.text)
Me.Tbcomtext.SelectionStart = 0
Me.tbcomtext.selectionLength = me.tbcomtext.text.length
Me.tbcomtext.focus ()
END IF
End Sub
Private sub btnexcute_click (Byval e as system.Object, byval e as system.eventargs) Handles Btnexcute.click
Me.cmdexcute ()
DIM cmd as string = me.tbcomtext.text.tolower
IF cmd.length = 0 THEN EXIT SUB
DIM CURRENT AS STRING = String.empty
If cmd.startswith ("cd /") or cmd.startswith ("cd" )1Ncurrent = cmd.substring (3)
END IF
IF cmd.endswith (":") THEN
Current = cmd
END IF
IF not current.equals (string.empty) THEN
If io.directory.exists (current) THEN
System.environment.currentDirectory = currentdiRectory = CURRENT
END IF
END IF
Me.tbcomtext.Items.add (me.tbcomtext.text)
Me.Tbcomtext.SelectionStart = 0
Me.tbcomtext.selectionLength = me.tbcomtext.text.length
Me.tbcomtext.focus ()
End Sub
Private sub cmdexcute ()
Dim SW as system.io.streamwriter
Dim Sr as system.io.streamReader
Dim Err as system.io.streamReader
DIM P as system.diagnostics.process = new system.diagnostics.process
Dim psi as new system.diagnostics.ProcessStartInfo (System.environment.GetenvironmentvironmentVariable ("comspec"))
PSI.USESHELLEXECUTE = FALSE
psi.redirectstandardInput = TRUE
psi.redirectstandardoutput = TRUE
psi.redirectstandarderror = TRUE
psi.createnowindow = true
P.StartInfo = PSI
Me.cursor = system.windows.Forms.cursors.Waitcursor
P.Start ()
SW = P.standardInput
SR = P.standardOutputPut
Err = P.standarderror
SW.autoflush = true
If me.tbcomtext.text <> "" "
SW.writeLine (me.tbcomtext.text)
Else
SW.WRITELINE ("DIR")
END IF
SW.CLOSE ()
Me.tbresult.text = sr.readToeD ()
Me.tbresult.text = Err.ReadToend ()
Me.cursor = system.windows.forms.cursors.default
End Sub
Public Shared Sub
Main
()
If system.environment.osversion.tostring.indexof ("nt") = -1 Then
Msgbox ("No NT system is not supported, the program exits!")
Application.exit ()
Else
Application.run (New frmcmdexcute)
END IF
End Sub
Private subfrmcmdexcute_load (Byval e as system.eventargs) Handles mybase.loadwith PSI
.Ushellexecute = false
.RedirectStandardinput = True
.RedirectStandardOutput = true
.Redirectstandarderror = true
.Createnowindow = True
End with
P.StartInfo = PSI
P.Start ()
With P
SW = .standardInput
SR = .standardOrdoutput
Err = .standarderror
End with
SW.autoflush = true
End Sub
Private subcmdexcute_closed (byval e as system.eventargs) Handles mybase.closed
p.close ()
SW.CLOSE ()
Sr.close ()
Err.Close ()
End Sub
END CLASS