VB回显DOS命令

高手帮帮忙啊VB回显DOS命令点按钮1执行文本框1的数据在文本框2中显示... 高手帮帮忙啊 VB回显DOS命令

点 按钮1 执行 文本框1 的数据 在 文本框2 中显示
展开
 我来答
ARTERIOSCLEROS
2008-06-29 · TA获得超过4183个赞
知道大有可为答主
回答量:1672
采纳率:0%
帮助的人:2425万
展开全部
给你个简单方便的程序。
创建如下控件:
Command1,Text1,Text2,Timer1.
设置Text2.MultiLine=True。(一定!)
在Text1中输入Dos命令,单击按钮,稍候片刻,在Text2中显示结果。
===========================
Const p = "d:\a.txt"
Private Sub Command1_Click()
Text2.Text = ""
Timer1.Enabled = False
Dim t As String
Shell "cmd /c" & Text1.Text & ">" & p
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Timer1.Enabled = False
Open p For Input As 1
Do While EOF(1) = False
Line Input #1, t
Text2.Text = Text2.Text + t
Loop
Close 1
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
Worsley_Barbar
2008-06-28 · TA获得超过313个赞
知道小有建树答主
回答量:382
采纳率:0%
帮助的人:0
展开全部
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const STILL_ALIVE = &H103
Private Sub Command1_Click()
'On Error Resume Next
Dim tmp As String '临时文件名
Dim tmp1 As String '临时文件内容
Dim strCommand As String 'DOS命令集
Dim pid As Long, hProcess As Long, i As Long
Text2 = ""
strCommand = Trim(Replace(Text1, vbCrLf, " & "))
If strCommand = "" Then Exit Sub
tmp = "c:\1.txt"
pid = Shell("cmd.exe /c " & strCommand & ">" & tmp, vbHide) ' vbHide)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
Do
Call GetExitCodeProcess(hProcess, ExitCode)
DoEvents
Loop While ExitCode = STILL_ALIVE
If Dir(tmp) <> "" Then
Open tmp For Input As #1
While EOF(1) = False
Line Input #1, tmp1
Text2 = Text2 + tmp1 + vbCrLf
Wend
Close #1
Kill tmp
End If
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式