procedure ShowProcessinfo(Processid:Cardinal);<br>var<br> h: THandle;<br> fileName: string;<br> iLen: integer;<br> hMod: HMODULE;<br> cbNeeded: DWORD;<br>begin<br> h := OpenProcess(PROCESS_ALL_ACCESS, false,Processid ); <br> if h > 0 then<br> begin<br> if EnumProcessModules(h, @hMod, sizeof(hMod), cbNeeded) then<br> begin<br> SetLength(fileName, MAX_PATH);<br> iLen := GetModuleFileNameEx(h, hMod, PCHAR(fileName), MAX_PATH);<br> if iLen <> 0 then<br> begin<br> SetLength(fileName, StrLen(PCHAR(fileName)));<br> ShowMessage(fileName);<br> end;<br> end;<br> CloseHandle(h);<br> end;<br>end;<br><br>procedure TMainform.Button2Click(Sender: TObject);<br>var<br> PE: TProcessEntry32;<br> Found: boolean;<br> h: THandle;<br>begin<br> h := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);<br> PE.dwSize := SizeOf(TProcessEntry32);<br> Found := Process32First(h, PE);<br> while Found do<br> begin<br> if PE.szExeFile = 'WINWORD.EXE' then<br> begin<br> [red]ShowProcessinfo(PE.th32ProcessID);[/red]<br> Exit; //找到有Word的进程就退出<br> end;<br> Found := Process32Next(h, PE);<br> end;<br> ShellExecute(Handle, 'open', 'WINWORD.EXE', '', '', SW_SHOW); //没找到就运行<br>end;