Check, if a process is running
2007-08-20 14:09
337 查看
{ Check if a process from the task list is active. }
uses TlHelp32;
function processExists(exeFileName: string): Boolean;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
Result := False;
while Integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
begin
Result := True;
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if processExists('notepad.exe') then
ShowMessage('process is running')
else
ShowMessage('process not running');
end;
uses TlHelp32;
function processExists(exeFileName: string): Boolean;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
Result := False;
while Integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
begin
Result := True;
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if processExists('notepad.exe') then
ShowMessage('process is running')
else
ShowMessage('process not running');
end;
相关文章推荐
- Check to see if python script is running - Stack Overflow
- git --- If no other git process is currently running, this probably means a git process crashed in
- If no other git process is currently running, this probably means a git process crashed in this repo
- Linux / UNIX: Find out or determine if process pid is running
- git 复位出现If no other git process is currently running, this probably means a git process crashed in this repo
- If no other git process is currently running, this probably means a git process crashed in this repo
- git Bush应用崩溃If no other git process is currently running, this probably means a git process crashed
- check if a linux process is done using bash 检查进程是否在运行
- Linux / Unix Script: Simple Process Checker To Find Out If A Service Is Running or Not
- If no other git process is currently running, this probably means a git process crashed in this rep
- git错误解决---If no other git process is currently running...
- 小胖说事31------iOS 真机编译错误"“XXX”的 iPod" and run "XXX" again, or if "XXX" is still running
- Check if a given Binary Tree is SumTree
- Theserver is not reeady for publishing.Please check if the Publishing Tools on the serverare started
- This generally means that another instance of this process was already running or is hung in the deb
- 解决configure: error: Cannot find pam headers. Please check if your system is ready for pam module development
- OCSSD.BIN Process is Running in a Non-RAC Environment
- unable to connect to the adb. check if adb is installed correctly
- How do you check if a variable is an array in JavaScript? [duplicate]
- check android Media Scanner is running-检查Android Media Scanner 是否在运行