VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 判断一个程序启动完成?(不是结束)
发表评论(0)作者:, 平台:, 阅读:10198, 日期:2000-03-12
 


判断一个程序启动完成?(不是结束)



'将以下代码加入标准模块

Option Explicit

public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long,

ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long,

lpExitCode As Long) As Long

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


public Const PROCESS_QUERY_INFORMATION = &H400

public Const STATUS_PENDING = &H103&


'在需要的地方调用RunShell过程,如:res=RunShell("c:\windows\notepad.exe")

'返回值为真则程序结束

Public Function RunShell(cmdline As String) As Boolean

Dim hProcess As Long

Dim ProcessId As Long

Dim exitCode As Long

ProcessId = Shell(cmdline, 1)

hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)

Do

Call GetExitCodeProcess(hProcess, exitCode)

DoEvents

Loop While exitCode = STATUS_PENDING

Call CloseHandle(hProcess)

RunShell = True

End Function