VB怎么判断进程是否存在

来源:百度知道 编辑:UC知道 时间:2024/05/05 12:19:26
比如我想在点command1之后判断进程里面是否存在1.exe这个进程,如果不存在就运行D:\1.exe,如果存在则什么都不做.

建立一个模块,然后把下面代码复制过去。
调用如下:
if FindProcess("1.exe")=0 then
shell 1.exe
endif
OK!

‘=====Process.bas====
Option Explicit
Dim Recn As Long
'======================用于查找进程和终止进程的API函数常数定义================ =====
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long,