Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal
bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const PROCESS_QUERY_INFORMATION = &H400
'参数:进程ID
Function IsProcessIsRun(ByVal PID As Long) As Boolean
Dim hProcess As Long
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0&, PID)
If hProcess = 0 Then
IsProcessIsRun = False
Exit Function
End If
Call CloseHandle(hProcess)
IsProcessIsRun = True
End Function
博客展示了使用Windows API函数判断进程是否运行的代码。通过Declare语句声明OpenProcess和CloseHandle函数,定义常量PROCESS_QUERY_INFORMATION,编写IsProcessIsRun函数,利用OpenProcess尝试打开进程,根据返回值判断进程是否运行。
1万+

被折叠的 条评论
为什么被折叠?



