怎样在进程中查找有没有某个EXE文件运行(50分)

S

sunswim

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样在进程中查找有没有某个EXE文件运行
 
主要用下面几个
CreateToolhelp32Snapshot
Process32First
Process32Next
自己慢慢找吧
 
给出例程,分可以再加
 

var
hMutex:HWND;
Ret:Integer;
begin

hMutex := CreateMutex(Nil, False, '你要找的exe的名称');
Ret := GetLastError;
if Ret = Error_already_exists then
begin
MessageBox(Application.Handle, '已经有一个程序在本机运行!', '提示', MB_OK OR MB_ICONWARNING);
ReleaseMutex(hMutex) ;
end;
end;
 
你这个程序我放在按钮中,要找的程序没有运行,按第一次可以,再按一次,就提示了,可程序没有运行呀
 
var
hcrrentwindow:hwnd;
sztext:array[0..254] of char;
s:string;
begin
hcrrentwindow:=GetWindow(handle,GW_HWNDFIRST);
while hcrrentwindow<>0do
begin
if GetWindowtext(hcrrentwindow,@sztext,255)>0 then
begin
s:=strpas(@sztext);
if pos('Microsoft Excel',s)<>0 then
//如果发现含有Microsoft Excel的窗口将其关闭。
SendMessage(hcrrentwindow,WM_CLOSE,0,0);
Memo1.Lines.Add(s);
end;
hcrrentwindow:=GetWindow(hcrrentwindow,GW_HWNDNEXT);
end;
end;
 
没这么简单,因为WORD打开一个文件,标题就变了,所以我是用窗口的CLASSname
其它程序都没问题,就是CAD的classname是动态的,所以我想用它的主程序ACAD。EXE
动态查找classname,所以请高手指教
 
我在网上找到一个例程,可以查找EXE文件有没有运行,但是好像没用
var
hSnapshot: THandle;
lppe: TProcessEntry32;
begin
hSnapShot:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
lppe.dwSize:=Sizeof(lppe);
if Process32First(hSnapshot,lppe) then
while Process32Next(hSnapshot,lppe)do
if lppe.szExeFile=(指定程序的执行文件名) then
??
CloseHandle(hSnapshot);
 
findwindow('EXE名',NIL)
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1095372
 
type
TProcessInfo = Record
ExeFile:String;
//用来存放应用程序的文件名
ProcessID:DWORD;
//存放进程标识号
end;
ProcessInfo = ^TProcessInfo;

var
p:processinfo;
Plist:Tlist;
ok:bool;
processlisthandle:thandle;
// 进程列表的句柄
processstruct:tprocessentry32;
// 进程的结构,进程的信息都在这个结构里
begin
plist:=tlist.create;
plist.clear;
//利用Createtoolhelp32snapshot函数得到进程列表的句柄
processlisthandle:=createtoolhelp32snapshot(th32cs_snapprocess,0);
//首先给出进程结构的大小
processstruct.dwsize:=sizeof(processstruct);
ok:=process32first(processlisthandle,processstruct);
//得到第一个进程
while integer(ok) <> 0do
begin
new(p);
p.exefile:=processstruct.szexefile;
p.processid:=processstruct.th32processid;
plist.add(p);//结果放到plist中
ok:=process32next(processlisthandle,processstruct);
//找下一个进程
end;
end;

plist里存的就是所有当前进程中的程序。
 
多人接受答案了。
 
顶部