判断指定进程号的进程是否存在

时间:2021-01-27 09:58:59

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