VB中CMD问题

来源:百度知道 编辑:UC知道 时间:2024/06/07 07:23:51
2个text 一个button
怎么样做到CMD命令回显
详细代码+解释~~~~~
万分感谢
就是在文本输入命令 cmd...后 信息返回到文本中

'暂时能做到的是这个
'以后想到怎么隐藏窗口再告诉你

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Function ReadAllFromAny(oExec)

If Not oExec.StdOut.AtEndOfStream Then
ReadAllFromAny = oExec.StdOut.ReadAll
Exit Function
End If

If Not oExec.StdErr.AtEndOfStream Then
ReadAllFromAny = "STDERR: " + oExec.StdErr.ReadAll
Exit Function
End If

ReadAllFromAny = -1
End Function

Private Sub Command1_Click()
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec(Text1.Text)
Dim allres, tryCount

allres = ""
tryCount = 0

Do While True

Dim res
res = ReadAllFromAny(oExec)
If -1 = res Then
If tryCount > 10 And oExec.Status = 1 Then
Exit Do
End If
tryCount = tryCount + 1
Sleep 100
DoEv