说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

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

HTML文档下载 WORD文档下载 PDF文档下载
VB判断一个程序启动完成(不是结束)

'将以下代码加入标准模块
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
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘