哦,我只能得到FillDrivers的结果,而得不到FillProcesses的结果 ,请高手指教!!!
代码如下:unit winntinfo;interfaceuses InfoInt, Windows, Classes, ComCtrls, Graphics,Controls;type
TWinNTInfo = class(TInterfacedObject, IWin32Info)
private
FProcList: array of DWORD;
FDrvlist: array of Pointer;
FWinIcon: hICON;
procedure FillProcesses(ListView: TListView; ImageList: TImageList);
procedure FillDrivers(ListView: TListView; ImageList: TImageList);
procedure Refresh;
public
constructor Create;
destructor Destroy; override;
procedure FillProcessInfoList(ListView: TListView;
ImageList: TImageList);
//procedure ShowProcessProperties(Cookie: Pointer);
end;implementationuses SysUtils, PSAPI, ShellAPI, CommCtrl;const
SFailMessage = '列举当前进程出现错误,请确认 '+
'PSAPI.DLL 已经安装到你的系统中.';
SDrvName = 'driver';
SProcname = 'process';
ProcessInfoCaptions: array[0..4] of string = (
'正在运行的程序', '类型', '进程ID', '句柄', '优先权');function GetPriorityClassString(PriorityClass: Integer): string;
begin
case PriorityClass of
HIGH_PRIORITY_CLASS: Result := '高';
IDLE_PRIORITY_CLASS: Result := '空闲';
NORMAL_PRIORITY_CLASS: Result := '正常';
REALTIME_PRIORITY_CLASS: Result := '实时';
else
Result := Format('未知 ($%x)', [PriorityClass]);
end;
end;{ TWinNTInfo }constructor TWinNTInfo.Create;
begin
FWinIcon := LoadImage(0, IDI_WINLOGO, IMAGE_ICON, LR_DEFAULTSIZE,
LR_DEFAULTSIZE, LR_DEFAULTSIZE or LR_DEFAULTCOLOR or LR_SHARED);
end;destructor TWinNTInfo.Destroy;
begin
DestroyIcon(FWinIcon);
inherited Destroy;
end;procedure TWinNTInfo.FillDrivers(ListView: TListView;
ImageList: TImageList);
var
I: Integer;
DrvName: array[0..MAX_PATH] of char;
begin
for I := Low(FDrvList) to High(FDrvList) do
if GetDeviceDriverFileName(FDrvList[I], DrvName,
SizeOf(DrvName)) > 0 then
with ListView.Items.Add do
begin
Caption := DrvName;
SubItems.Add(SDrvName);
SubItems.Add(IntToHex(Integer(FDrvList[I]), 8));
end;
end;procedure TWinNTInfo.FillProcesses(ListView: TListView;
ImageList: TImageList);
var
I: Integer;
Count: DWORD;
ProcHand: THandle;
ModHand: HMODULE;
tAppIcon: tICON;
ModName: array[0..MAX_PATH] of char;
begin
for I := Low(FProcList) to High(FProcList) do
begin
ProcHand := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
False, FProcList[I]);
if ProcHand > 0 then
try
EnumProcessModules(Prochand, @ModHand, 1, Count);
if GetModuleFileNameEx(Prochand, ModHand, ModName,
SizeOf(ModName)) > 0 then
begin
tAppIcon.handle := ExtractIcon(HInstance, ModName, 0);
try
if tAppIcon.handle = 0 then tAppIcon.handle := FWinIcon;
with ListView.Items.Add, SubItems do
begin
Caption := ModName; // file name
Data := Pointer(FProcList[I]); // save ID
Add(SProcName); // "process"
Add(IntToStr(FProcList[I])); // process ID
Add('$' + IntToHex(ProcHand, 8)); // process handle
// priority class
Add(GetPriorityClassString(GetPriorityClass(ProcHand)));
// icon
if ImageList <> nil then
ImageIndex := imagelist.addicon(tappicon);
end;
finally
if tAppIcon.handle <> FWinIcon then DestroyIcon(tAppIcon.handle);
end;
end;
finally
CloseHandle(ProcHand);
end;
end;
end;procedure TWinNTInfo.FillProcessInfoList(ListView: TListView;
ImageList: TImageList);
var
I: Integer;
begin
Refresh;
ListView.Columns.Clear;
ListView.Items.Clear;
for I := Low(ProcessInfoCaptions) to High(ProcessInfoCaptions) do
with ListView.Columns.Add do
begin
if I = 0 then Width := 285
else Width := 75;
Caption := ProcessInfoCaptions[I];
end;
FillProcesses(ListView, ImageList); // Add processes to listview
FillDrivers(ListView, ImageList); // Add device drivers to listview
end;procedure TWinNTInfo.Refresh;
var
Count: DWORD;
BigArray: array[0..$3FFF - 1] of DWORD;
begin
// Get array of process IDs
if not EnumProcesses(@BigArray, SizeOf(BigArray), Count) then
raise Exception.Create(SFailMessage);
SetLength(FProcList, Count div SizeOf(DWORD));
Move(BigArray, FProcList[0], Count);
// Get array of Driver addresses
if not EnumDeviceDrivers(@BigArray, SizeOf(BigArray), Count) then
raise Exception.Create(SFailMessage);
SetLength(FDrvList, Count div SizeOf(DWORD));
Move(BigArray, FDrvList[0], Count);
end;end.
代码如下:unit winntinfo;interfaceuses InfoInt, Windows, Classes, ComCtrls, Graphics,Controls;type
TWinNTInfo = class(TInterfacedObject, IWin32Info)
private
FProcList: array of DWORD;
FDrvlist: array of Pointer;
FWinIcon: hICON;
procedure FillProcesses(ListView: TListView; ImageList: TImageList);
procedure FillDrivers(ListView: TListView; ImageList: TImageList);
procedure Refresh;
public
constructor Create;
destructor Destroy; override;
procedure FillProcessInfoList(ListView: TListView;
ImageList: TImageList);
//procedure ShowProcessProperties(Cookie: Pointer);
end;implementationuses SysUtils, PSAPI, ShellAPI, CommCtrl;const
SFailMessage = '列举当前进程出现错误,请确认 '+
'PSAPI.DLL 已经安装到你的系统中.';
SDrvName = 'driver';
SProcname = 'process';
ProcessInfoCaptions: array[0..4] of string = (
'正在运行的程序', '类型', '进程ID', '句柄', '优先权');function GetPriorityClassString(PriorityClass: Integer): string;
begin
case PriorityClass of
HIGH_PRIORITY_CLASS: Result := '高';
IDLE_PRIORITY_CLASS: Result := '空闲';
NORMAL_PRIORITY_CLASS: Result := '正常';
REALTIME_PRIORITY_CLASS: Result := '实时';
else
Result := Format('未知 ($%x)', [PriorityClass]);
end;
end;{ TWinNTInfo }constructor TWinNTInfo.Create;
begin
FWinIcon := LoadImage(0, IDI_WINLOGO, IMAGE_ICON, LR_DEFAULTSIZE,
LR_DEFAULTSIZE, LR_DEFAULTSIZE or LR_DEFAULTCOLOR or LR_SHARED);
end;destructor TWinNTInfo.Destroy;
begin
DestroyIcon(FWinIcon);
inherited Destroy;
end;procedure TWinNTInfo.FillDrivers(ListView: TListView;
ImageList: TImageList);
var
I: Integer;
DrvName: array[0..MAX_PATH] of char;
begin
for I := Low(FDrvList) to High(FDrvList) do
if GetDeviceDriverFileName(FDrvList[I], DrvName,
SizeOf(DrvName)) > 0 then
with ListView.Items.Add do
begin
Caption := DrvName;
SubItems.Add(SDrvName);
SubItems.Add(IntToHex(Integer(FDrvList[I]), 8));
end;
end;procedure TWinNTInfo.FillProcesses(ListView: TListView;
ImageList: TImageList);
var
I: Integer;
Count: DWORD;
ProcHand: THandle;
ModHand: HMODULE;
tAppIcon: tICON;
ModName: array[0..MAX_PATH] of char;
begin
for I := Low(FProcList) to High(FProcList) do
begin
ProcHand := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
False, FProcList[I]);
if ProcHand > 0 then
try
EnumProcessModules(Prochand, @ModHand, 1, Count);
if GetModuleFileNameEx(Prochand, ModHand, ModName,
SizeOf(ModName)) > 0 then
begin
tAppIcon.handle := ExtractIcon(HInstance, ModName, 0);
try
if tAppIcon.handle = 0 then tAppIcon.handle := FWinIcon;
with ListView.Items.Add, SubItems do
begin
Caption := ModName; // file name
Data := Pointer(FProcList[I]); // save ID
Add(SProcName); // "process"
Add(IntToStr(FProcList[I])); // process ID
Add('$' + IntToHex(ProcHand, 8)); // process handle
// priority class
Add(GetPriorityClassString(GetPriorityClass(ProcHand)));
// icon
if ImageList <> nil then
ImageIndex := imagelist.addicon(tappicon);
end;
finally
if tAppIcon.handle <> FWinIcon then DestroyIcon(tAppIcon.handle);
end;
end;
finally
CloseHandle(ProcHand);
end;
end;
end;procedure TWinNTInfo.FillProcessInfoList(ListView: TListView;
ImageList: TImageList);
var
I: Integer;
begin
Refresh;
ListView.Columns.Clear;
ListView.Items.Clear;
for I := Low(ProcessInfoCaptions) to High(ProcessInfoCaptions) do
with ListView.Columns.Add do
begin
if I = 0 then Width := 285
else Width := 75;
Caption := ProcessInfoCaptions[I];
end;
FillProcesses(ListView, ImageList); // Add processes to listview
FillDrivers(ListView, ImageList); // Add device drivers to listview
end;procedure TWinNTInfo.Refresh;
var
Count: DWORD;
BigArray: array[0..$3FFF - 1] of DWORD;
begin
// Get array of process IDs
if not EnumProcesses(@BigArray, SizeOf(BigArray), Count) then
raise Exception.Create(SFailMessage);
SetLength(FProcList, Count div SizeOf(DWORD));
Move(BigArray, FProcList[0], Count);
// Get array of Driver addresses
if not EnumDeviceDrivers(@BigArray, SizeOf(BigArray), Count) then
raise Exception.Create(SFailMessage);
SetLength(FDrvList, Count div SizeOf(DWORD));
Move(BigArray, FDrvList[0], Count);
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货