在Visual Basic 2005中怎样执行外部的程序

 我来答
彤面定开大来0H
2008-07-31 · TA获得超过175个赞
知道答主
回答量:145
采纳率:0%
帮助的人:0
展开全部
要用到API函数
实现代码如下:
首先在部件里把控件:Microsoft Common Dialog Control 6.0勾上,再在窗体上加个新出来的Commondialog控件
再复制如下代码

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Private Const INFINITE = &HFFFF

Private Const SYNCHRONIZE = &H100000

Private Sub Form_Click()
On Error Resume Next
CommonDialog1.Filter = "(*.exe)|" + "*.exe"
CommonDialog1.ShowOpen
a = CommonDialog1.FileName
Form1.Hide
i = Shell(a, vbNormalFocus)
p = OpenProcess(SYNCHRONIZE, False, i)
r = WaitForSingleObject(p, INFINITE)
r = CloseHandle(p)
MsgBox "调用的处部程序被关闭"
Form1.Show
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式