T
taibu
Unregistered / Unconfirmed
GUEST, unregistred user!
从网上找到下面方法,但不成功,不知问题在哪,各位还有其它更好的方法吗?
function TForm1.EnumProcessNT(var ProcArray: TProcessNTArray): Integer;
var
i : Integer;
Count : DWORD;
ProcHand : THandle;
ModHand : HMODULE;
pList : array of DWORD;
ModName : array[0..MAX_PATH] of char;
BigArray : array[0..$3FFF-1] of DWORD; //大数组,因为不知道能预分配内存大小
begin
if not EnumProcesses(@BigArray,SizeOf(BigArray),Count) then raise Exception.Create('sFailMessage');
Result := Count Div SizeOf(DWORD);
SetLength(pList,Result);
Move(BigArray,pList[0],Count);
SetLength(ProcArray,Result);
for i:= low(pList) to High(pList) do
begin
procHand := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
False,pList);
if procHand >0 then
try
EnumProcessModules(ProcHand,@ModHand,1, Count);
if GetModuleFileName(ProcHand,ModName, SizeOf(ModName))>0 then
with ProcArray do
begin
pID := pList;
szExeFile := strPas(ModName);
pHandle := ProcHand;
pPriClass := GetPriorityClass(ProcHand);
end;
finally
CloseHandle(procHand);
end;
end;
end;
function TForm1.EnumProcessNT(var ProcArray: TProcessNTArray): Integer;
var
i : Integer;
Count : DWORD;
ProcHand : THandle;
ModHand : HMODULE;
pList : array of DWORD;
ModName : array[0..MAX_PATH] of char;
BigArray : array[0..$3FFF-1] of DWORD; //大数组,因为不知道能预分配内存大小
begin
if not EnumProcesses(@BigArray,SizeOf(BigArray),Count) then raise Exception.Create('sFailMessage');
Result := Count Div SizeOf(DWORD);
SetLength(pList,Result);
Move(BigArray,pList[0],Count);
SetLength(ProcArray,Result);
for i:= low(pList) to High(pList) do
begin
procHand := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
False,pList);
if procHand >0 then
try
EnumProcessModules(ProcHand,@ModHand,1, Count);
if GetModuleFileName(ProcHand,ModName, SizeOf(ModName))>0 then
with ProcArray do
begin
pID := pList;
szExeFile := strPas(ModName);
pHandle := ProcHand;
pPriClass := GetPriorityClass(ProcHand);
end;
finally
CloseHandle(procHand);
end;
end;
end;