Well, really thanks Tom, your code work 100% !!!
I tried to Get STD_OUTPUT_HANDLE from my GUI application, but with no
success.
This is what i done:
-I tried to create a new thread and launch a process from there, but the
Handle returned is ever the one of my gui application.
-Then i triend to create a new thread and launch a Shell from there, but
the Handle returned is ever the one of my gui application.
In Vb 6.0 is possible to create a Console and get his Handle by calling
the API AllocConsole, this is a little part of code:
Api Declaration:
Private Declare Function AllocConsole Lib "kernel32" () As Long
And the code o my button1:
AllocConsole
Shell "cmd /k dir c:\"
StdOut = GetStdHandle(STD_OUTPUT_HANDLE)
The follow of the code is similar the one you gived me...
I hope this should help.....
And i hope of you should help me
Regards.
Stefano
Is this what your after:
Option Explicit On
Option Strict On
Imports System.Diagnostics.Process
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
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
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Anchor =
CType((System.Windows.Forms.AnchorStyles.Bottom Or
System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
Me.Button1.Location = New System.Drawing.Point(284, 260)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'ListBox1
'
Me.ListBox1.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.ListBox1.IntegralHeight = False
Me.ListBox1.Location = New System.Drawing.Point(0, 0)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(364, 256)
Me.ListBox1.TabIndex = 1
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(360, 285)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim p As New Process
ListBox1.Items.Clear()
p.StartInfo.FileName = "cmd"
p.StartInfo.Arguments = "/k dir c:\"
p.StartInfo.CreateNoWindow = True
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.Start()
Dim output As String = p.StandardOutput.ReadLine()
Do Until output Is Nothing
ListBox1.Items.Add(output)
output = p.StandardOutput.ReadLine()
Loop
End Sub
End Class
HTH,
Tom Shelton