Computing.Net > Forums > Programming > Read cmd windows from VB6

Read cmd windows from VB6

Reply to Message Icon

Original Message
Name: szx
Date: February 5, 2003 at 07:34:46 Pacific
Subject: Read cmd windows from VB6
OS: 2000
CPU/Ram: OK
Comment:

I run a shell command to start the cmd.exe and issue a ping command to network using SendKeys. I wonder how can I read the result from my VB app. if any VB expert can give me a clue, I appreciate!

Thanx


Report Offensive Message For Removal

Response Number 1
Name: Fred Lyhne
Date: February 7, 2003 at 15:45:27 Pacific
Subject: Read cmd windows from VB6
Reply: (edit)

Declare a couple of API's & constants
(Watch fore line wrap)
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFF
Private Declare Function WaitForSingleObject Lib "kernel32" Alias "WaitForSingleObject" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

REM then something like this:
Private Sub Command1_Click()
Dim TaskId As Long, ProcessHandle As Long
Open App.Path & "\My.Bat" For Output As #1
Print #1, "ping Microsoft.com > " & App.Path & "\OutputfromMyBat.txt"
Close 1
REM since VB is faster with inline code than the respose from the commnd we need to make sure the process is finished

TaskId = Shell(App.Path & "\my.bat", vbMinimizedNoFocus)
ProcessHandle = OpenProcess(SYNCHRONIZE, True, TaskId)
WaitForSingleObject ProcessHandle, INFINITE
Open App.Path & "\OutputfromMyBat.txt" For Input As #1
REM Make sure text1's multiline prpty is true
Text1.Text = Input(LOF(1), 1)
Close 1
End Sub


Report Offensive Follow Up For Removal

Response Number 2
Name: szx
Date: February 10, 2003 at 10:52:31 Pacific
Subject: Read cmd windows from VB6
Reply: (edit)

Thanks, Fred

It's works perfect!

szx


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Read cmd windows from VB6

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software