如何取得进程的句柄数量(非线程数量)(100)

  • 主题发起人 主题发起人 drizzledu
  • 开始时间 开始时间
D

drizzledu

Unregistered / Unconfirmed
GUEST, unregistred user!
如何取得进程的句柄数量(非线程数量),请给个代码,谢谢,
 
当前进程列表 (注意uses TLHelp32)var lppe: TProcessEntry32; found : boolean; Hand : THandle;begin Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0); found := Process32First(Hand,lppe); while found do begin ListBox.Items.Add(StrPas(lppe.szExeFile));//列出所有进程。 found := Process32Next(Hand,lppe); end;end;
 
lppe.szExeFile 这个不是程式名吗?
 
看看msdn:GetProcessHandleCount
 
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TPDWord = ^DWORD; TProcessInfo = record dwOffset: DWORD; dwThreadCount: DWORD; dwUnknown1: array[0..5] of DWORD; ftCreationTime: TFileTime; ftUserTime: TFileTime; ftKernelTime: TFileTime; // dwUnknown4: DWORD; // dwUnknown5: DWORD; dwUnknown6: DWORD; pszProcessName: pwideChar; dwBasePriority: DWORD; dwProcessID: DWORD; dwParentProcessID: DWORD; dwHandleCount: DWORD; dwUnknown7: DWORD; dwUnknown8: DWORD; dwVirtualBytesPeak: DWORD; dwVirtualBytes: DWORD; dwPageFaults: DWORD; dwWorkingSetPeak: DWORD; dwWorkingSet: DWORD; dwUnknown9: DWORD; dwPagedPool: DWORD; dwUnknown10: DWORD; dwNonPagedPool: DWORD; dwPageFileBytesPeak: DWORD; dwPageFileBytes: DWORD; dwPrivateBytes: DWORD; dwUnknown11: DWORD; dwUnknown12: DWORD; dwUnknown13: DWORD; dwUnknown14: DWORD; ati: array[0..0] of TThreadInfo; end; PProcessInfo = ^TProcessInfo;var NtQuerySystemInformation: function(infoClass: DWORD; buffer: Pointer;bufSize: DWORD; returnSize: TPDword): DWORD; stdcall = nil;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var buf:array[0..299999] of char; pi:PProcessInfo; t,h,count:Integer; //t:线程数,h:句柄数begin if @NtQuerySystemInformation = nil then NtQuerySystemInformation := GetProcAddress(GetModuleHandle('ntdll.dll'),'NtQuerySystemInformation'); NtQuerySystemInformation(5, @buf, 300000, nil); pi:=@buf; t:=0;h:=0;count:=0; repeat inc(count); t:=t+pi^.dwThreadCount; h:=h+pi^.dwHandleCount; pi:=pointer(cardinal(pi)+pi^.dwOffset); until pi^.dwOffset=0; //获得为0时的情况 t:=t+pi^.dwThreadCount; h:=h+pi^.dwHandleCount; inc(count); showmessage(inttostr(h));end;end.
 
浪人情哥谢谢, 待会给分
 
多人接受答案了。
 
后退
顶部