在Visual Basic 2005中怎样执行外部的程序
展开全部
要用到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
实现代码如下:
首先在部件里把控件: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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询