我这段代码哪错了,关于读取WinXP进程的代码????????????急(100分)

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