uses ShellAPI,TlHelp32;var PE:TProcessEntry32; Found:boolean; h:THandle; begin h:=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0); PE.dwSize:=SizeOf(TProcessEntry32); Found:=Process32First(h,PE); while Found do begin if PE.szExeFile='WINWORD.EXE' then Exit; //找到有Word的进程就退出 Found := Process32Next(h,PE); end; ShellExecute(Handle,'open','WINWORD.EXE','','',SW_SHOW);//没找到就运行 end;
Found:boolean;
h:THandle;
begin
h:=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
PE.dwSize:=SizeOf(TProcessEntry32);
Found:=Process32First(h,PE);
while Found do
begin
if PE.szExeFile='WINWORD.EXE' then Exit; //找到有Word的进程就退出
Found := Process32Next(h,PE);
end;
ShellExecute(Handle,'open','WINWORD.EXE','','',SW_SHOW);//没找到就运行
end;