1,184
社区成员
发帖
与我相关
我的任务
分享
NtQuerySystemInformation 是 Windows 系统的内部函数,由它可以得到许多种类的系统
信息。这个函数在 Windows 的未来版本中可能会有改变或被替代。
微软在自己的网站上贴出的函数原型如下:
NTSTATUS NtQuerySystemInformation(
SYSTEM_INFORMATION_CLASS SystemInformationClass,
PVOID SystemInformation,
ULONG SystemInformationLength,
PULONG ReturnLength);
翻译成 Delphi 语法大概是这样吧:
function NtQuerySystemInformation(
SystemInformationClass:DWord; // 这个参数最终根据需要取得的信息而变
SystemInformation:Pointer; // 这个参数指向接收取来的信息的缓存结构
SystemInformationLength:DWord; // 这个参数指出上面这个缓存结构的大小
ReturnLength:DWord):DWord;stdcall; // 这个参数指出实际返回的数据的大小
于是可以在 Delphi 程序中使用下面的语法调用这个函数:
function NtQuerySystemInformation; external 'NTdll.dll' name 'NtQuerySystemInformation';
这个函数的参数变化实在太多,对每个参数都一一作类型声明的话,会很累的,还不如在想用它的时候,
直接用合适的值代进去拉倒。
在这个 DLL 中,获取相关的信息的函数还有很多,可以使用 PE View 工具看它的 Export 段,比如:
NtQueryInformationProcess
NtQueryInformationThread
等等。这些函数可以在 Windows NT中使用...... unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, TLHelp32,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TProcessInfo = Record
ExeFile : String;
ProcessID : DWORD;
end;
pProcessInfo = ^TProcessInfo;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var p : pProcessInfo;
ContinueLoop:BOOL;
var
FSnapshotHandle:THandle;
FProcessEntry32:TProcessEntry32;
begin
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);
while integer(ContinueLoop)......