程序中如何判断qq进程正在打开或即将启动(20分)

  • 主题发起人 主题发起人 zscczj
  • 开始时间 开始时间
Z

zscczj

Unregistered / Unconfirmed
GUEST, unregistred user!
能否给个例程
 
不是吧,我也想知道阿,我还想知道,windows是怎么运行的呢
 
可以根据FindWindow()函数去查找
 
TreminateProcessByName('f:/qq.exe');<br><br><br>//------------------------------------------------------------------------------<br>function TreminateProcessByName(Const ExeFile:string):Boolean;<br>var<br>&nbsp; p: TProcessInfo;<br>&nbsp; ContinueLoop: Boolean;<br>&nbsp; FSnapshotHandle: THandle;<br>&nbsp; FProcessEntry32: TProcessEntry32;<br>&nbsp; hh: HWND;<br>begin<br>&nbsp; Result:=False;<br>&nbsp; FSnapshotHandle := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br>&nbsp; try<br>&nbsp; &nbsp; FProcessEntry32.dwSize := SizeOf(FProcessEntry32);<br>&nbsp; &nbsp; ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);<br>&nbsp; &nbsp; while integer(ContinueLoop) &lt;&gt; 0 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if fcISNT then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; hh := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, FProcessEntry32.th32ProcessID);<br>&nbsp; &nbsp; &nbsp; &nbsp; if hh &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if GetModuleFileNameEx(hh, 0,FProcessEntry32.szExeFile,SizeOf(FProcessEntry32.szExeFile)) = 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StrPCopy(FProcessEntry32.szExeFile, '[Idle]');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hh);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; p.ExeFile := FProcessEntry32.szExeFile;<br><br>&nbsp; &nbsp; &nbsp; if lowercase(p.ExeFile)=lowercase(ExeFile) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; p.ProcessID := FProcessEntry32.th32ProcessID;<br>&nbsp; &nbsp; &nbsp; &nbsp; hh := OpenProcess(PROCESS_ALL_ACCESS, true, p.ProcessID);<br>&nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TerminateProcess(hh, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application.MessageBox('QQ禁止在本机运行,请与管理员联系!', '禁止运行',MB_ICONINFORMATION + MB_OK);<br>&nbsp; &nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hh);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; CloseHandle(FSnapshotHandle);<br>&nbsp; end;<br>end;
 
如果只是想禁止qq的运行,<br>那么只要查找窗口,一旦发现qq的窗口,直接关闭它就可以了,没有必要向楼上这么<br>多代码啊
 
最简单的方法,就是用Timer来使用Findwindow
 
后退
顶部