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