在VB6.0中用shell执行的程序,如何判断其是否结束?

Barry111 2004-05-09 11:51:39
在VB4.0中好像用GetModuleUsage()就可以判断,但在6.0中好像没有这个函数了,
那位知道改如何判断用shell执行的程序是否结束,是不是在6.0中也有对应的一个函数?
...全文
452 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wumy_ld 2004-05-09
  • 打赏
  • 举报
回复
可以参考:
Shell一个应用程序并等待该程序执行完毕后继续运行:
http://www.xhstudio.net/show.asp?id=2177
顺序调用多个可执行文件:
http://www.china-askpro.com/msg1/qa21.shtml
使用Shell指令具有Wait的功能:
http://school.enet.com.cn/eschool/inforcenter/A20040324297013.html
tangxiaosan001 2004-05-09
  • 打赏
  • 举报
回复
搞了这么多就说id啊。我学习来的咯
wumy_ld 2004-05-09
  • 打赏
  • 举报
回复
'以下例子演示如何打开一个应用程序并等待执行完毕,之后关闭自己。

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

Dim pID As Long

Function StillRun(ByVal ProgramID) As Boolean
Dim lHProgram As Long
Dim lReturn As Long

hProgram = OpenProcess(0, False, ProgramID)
If Not hProgram = 0 Then
StillRun = True
Else
StillRun = False
End If
CloseHandle hProgram
End Function

Private Sub Form_Load()
If Dir$("c:\windows\cdplayer.exe") <> "" Then
Me.Show
pID = Shell("c:\windows\cdplayer.exe")
While StillRun(pID)
DoEvents
Wend
End
Else
MsgBox "没有找到CD播放器"
End
End If
End Sub
Barry111 2004-05-09
  • 打赏
  • 举报
回复
谢谢kissoflife,我给据你的做法,稍加改动撮成功了,
如下:
在一般模块中:
Public Const SYNCHRONIZE = &H100000
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

具体运用:
Dim pID As Long, pHnd As Long ' 分别声明 Process Id 及 Process Handle 变数
pID = Shell(App.Path + "\WENNER.exe", 1)
II = MsgBox(" 提示:正在运行,DOS窗口结束后按回车键 ...", 0, " 运行接地电阻计算程序")
StillRun1 = True
While StillRun1
pHnd = OpenProcess(SYNCHRONIZE, 0, pID)
If pHnd <> 0 Then
StillRun1 = True
Else
StillRun1 = False
End If
CloseHandle pHnd
Wend

再次感谢

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧