vb怎样直接调用dos命令执行的结果?

来源:百度知道 编辑:UC知道 时间:2024/06/24 13:28:33
比如我 shell "cmd /c ipconfig",0
然后直接将结果msgbox 显示出来。

不要那种先写入文本(shell "cmd /c ipconfig > temp.exe")再读文本的,那样效率太慢,操作起来也相当麻烦。

我以前听说过有人可以用什么createpipe等api函数实现的,好像是命令管道什么的,有人知道吗?知道的话请帮忙一下,先谢谢了,最好给出代码
。。。我刚刚也搜到这个东西了,拜托给点代码好不?

鲸无敌的不错,在VB吧就闻此大名,今日一见果然名不虚传
我已经将你的那个封装一个函数了哈,直接调用了 呵呵
Private Sub Command1_Click()
    MsgBox retunCmdResult("cmd /c ipconfig")
End Sub

Option Explicit

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const STARTF_USESTDHANDLES = &H100&
Private Const STARTF_USESHOWWINDOW = &H1

Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type

Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

Private Declare Function CreatePipe Lib