给定_filename应用程序的路径全名,检查是否已启动或进程已存在
function CheckFileNameIsProcess(_filename: string): boolean;
var
h:THandle;
fileName:string;
iLen:integer;
hMod:HMODULE;
cbNeeded
WORD;
processesID:array[0..1024] of DWORD;
buffNeeded
WORD;
processCount
WORD;
index:integer;
begin
EnumProcesses(@processesID,sizeof(processesID),buffNeeded);
processCount:=buffNeeded div sizeof(DWORD);
for index:=0 to processCount-1 do
begin
h:=OpenProcess(PROCESS_ALL_ACCESS,false,processesID[index]);
if h>0 then
begin
if EnumProcessModules(h,@hMod,sizeof(hMod),cbNeeded)then
begin
SetLength(fileName,MAX_PATH);
iLen:=GetModuleFileNameEx(h,hMod,PCHAR(fileName),MAX_PATH);
if iLen<>0then
begin
SetLength(fileName,StrLen(PCHAR(fileName)));
if(UpperCase(filename)=UpperCase(trim(_filename)))then
MessageBox(self.ParentHandle,'程序已启动!','提示',MB_OK);
end;
end;
CloseHandle(h);
end;
end;
end;
改一改可以获取所有进程的文件路径
copy别人的