unit unit1;
inte***ce
uses
winapi.windows, winapi.messages, system.sysutils, system.variants, system.classes, vcl.graphics,
vcl.controls, vcl.forms, vcl.dialogs, vcl.stdctrls; // , psapi, tlhelp32;
type
t物件控制代碼 = class(tform)
button2: tbutton;
label1: tlabel;
txtpid: tedit;
procedure button2click(sender: tobject);
private
public
end;
type
system_handle = packed record
processid: dword;
handletype: word;
handlenumber: word;
kerneladdress: dword;
flags: dword;
end;
tobject_information_class = (objectbasicinformation, objectnameinformation, objecttypeinformation, objectalltypesinformation, objecthandleinformation);
system_handle_information = packed record
count: dword;
handles: system_handle;
end;
pntquerysysteminformation = function(systeminformationclass: dword; systeminformation: pointer; systeminformationlength: ulong; returnlength: pulong): dword; stdcall;
pntqueryobject = function(objecthandle: thandle; objectinformationclass: tobject_information_class; objectinformation: pointer; objectinformationlength: dword;
returnlength: pdword): dword; stdcall;
var物件控制代碼: t物件控制代碼;
implementation
function getprocesshandlecount(const pid: dword): integer;
const
cidefaultsize = $2000;
varret: cardinal;
i: integer;
pdata: ^system_handle_information;
pi: ^system_handle;
modulehandle: dword;
ntqueryobject: pntqueryobject;
ntquerysysteminformation: pntquerysysteminformation;
begin
pdata := nil;
result := 0;
ret := 0;
// 提公升程式許可權,提公升debug許可權的**很多,從網路照抄即可
// enableprivilege('sedebugprivilege', true);
modulehandle := getmodulehandle('ntdll.dll');
ntqueryobject := getprocaddress(modulehandle, 'ntqueryobject');
ntquerysysteminformation := getprocaddress(loadlibrary('ntdll.dll'), 'ntquerysysteminformation');
pdata := allocmem(cidefaultsize);
tryntquerysysteminformation(16, pdata, cidefaultsize, @ret); // 16,表明systeminformationclass是handle,獲取系統所有控制代碼資訊
if ret > cidefaultsize then
begin
reallocmem(pdata, ret);
if pdata = nil then
exit;
if ntquerysysteminformation(16, pdata, ret, @ret) <> 0 then
exit;
end;
pi := @pdata.handles;
for i := 0 to pdata.count - 1 do
begin
if pi.processid = pid then
begin
inc(result);
end;
inc(pi);
end;
finally
if pdata <> nil then
freemem(pdata);
end;
end;
procedure t物件控制代碼.button2click(sender: tobject);
varpid, count: integer;
begin
if txtpid.text = '' then
begin
showmessage('pid不能為空!');
exit;
endelse
begin
pid := strtoint(txtpid.text);
count := getprocesshandlecount(pid);
label1.caption := '控制代碼總數:' + inttostr(count);
end;
end;
end.
以上**在winxpsp3,delphixe2通過
關於獲取程序控制代碼的問題
使用createprocess建立乙個程序後,process information結構中會包含程序的handle,和唯一存在的程序id 而後使用openprocess開啟程序時,根據第乙個引數 dwdesiredaccess 想擁有的該程序訪問許可權 process all access 所有能獲...
關於獲取程序控制代碼的問題
使用createprocess建立乙個程序後,process information結構中會包含程序的handle,和唯一存在的程序id 而後使用openprocess開啟程序時,根據第乙個引數 dwdesiredaccess 想擁有的該程序訪問許可權 process all access 所有能獲...
C 根據程序名稱獲取程序的控制代碼?
c 根據程序名稱獲取程序的控制代碼或c 如何獲取其他程序的控制代碼?有時候標題名是動態變化的,所以不使用findwindow方法!structlayout layoutkind.sequential public struct processentry32 dllimport kernel32.dl...