J
jxhdy2001
Unregistered / Unconfirmed
GUEST, unregistred user!
资料介绍通信NTQuerySystemInforamtion可以得到线程的状态?可调用那函数总是出错<br>const<br> SystemBasicInformation = 0;<br> SystemPerformanceInformation = 2;<br> PROCESS_INFORMATION = 5; //ProcessesInfo<br> DRIVER_INFORMATION= 11;<br>type<br> TPDword=PWORD;<br> SYSTEM_THREADS=^TthreadInfo;<br> TthreadInfo=Packed Record<br> DwUnKnown1 : DWORD;<br> dwStartAddress: DWORD;<br> dwOwningPID : DWORD;<br> dwThreadID : DWORD;<br> dwCurrentPriority: DWORD;<br> dwBasepriority: DWORD;<br> dwContextSwitches: DWORD;<br> dwThreadState : DWORD;<br> dwWaitReason : DWORD;<br> dwUnknown2 : DWORD;<br> end;<br><br> TVM_COUNTERS=^_VM_COUNTERS;<br> _VM_COUNTERS=record<br> PeakVirtualSize :ULONG; //虚拟存储峰值大小;<br> VirtualSize :ULONG; //虚拟存储大小;<br> PagedFaultCount :ULONG;<br> PeakWorkingSetSize:ULONG;<br> WorkingSetSize :ULONG;<br> QuotaPeakPagedPoolUsage:ULONG;<br> QuotaPagedPoolUsage:ULONG;<br> QuotaPeakNonPagedPoolUsage:ULONG;<br> QuotaNonPagedPoolUsage:ULONG;<br> PagefileUsage :ULONG;<br> PeakPagefileUsage :ULONG;<br> end;<br><br> TIO_COUNTERS=^_IO_COUNTERS;<br> _IO_COUNTERS=record<br> ReadOperationCount: LARGE_INTEGER; //I/O读操作数目;INTEGER<br> WriteOperationCount: LARGE_INTEGER; //I/O写操作数目;<br> OtherOperationCount: LARGE_INTEGER; //I/O其他操作数目;<br> ReadTransferCount: LARGE_INTEGER; //I/O读数据数目;<br> WriteTransferCount: LARGE_INTEGER; //I/O写数据数目;<br> OtherTransferCount: LARGE_INTEGER; //I/O其他操作数据数目;<br> end;<br><br> PSYSTEM_PROCESSES=^TSYSTEM_PROCESSES;<br> TSYSTEM_PROCESSES=packed record<br> NextEntryDelta: ULONG; //构成结构序列的偏移量;<br> ThreadCount: ULONG; //线程数目;<br> Reserved1: array [0..6] of ULONG; //<br> CreateTime: LARGE_INTEGER; //创建时间;<br> UserTime: LARGE_INTEGER; //用户模式(Ring 3)的CPU时间;<br> KernelTime: LARGE_INTEGER; //内核模式(Ring 0)的CPU时间;<br> ProcessName: STRING; //进程名称;UNICODE_<br> BasePriority: ULONG; //进程优先权;<br> ProcessId: ULONG; //进程标识符;<br> InheritedFromProcessId: ULONG; //父进程的标识符;<br> HandleCount:ULONG; //句柄数目;<br> Reserved2:array [0..2]of ULONG; //[0..2]<br> VmCounters: TVM_COUNTERS; //虚拟存储器的结构,见下;<br> IoCounters: TIO_COUNTERS; //IO计数结构,见下;<br> Threads: array [0..1]of TthreadInfo; //进程相关线程的结构数组,见下;<br> end;<br>function NtQuerySystemInformation<br> (<br> infoClass: DWORD;<br> buffer: Pointer;<br> bufSize: DWORD;<br> returnSize: TPDword<br> ): DWORD;stdcall ;external 'ntdll.dll' name 'NtQuerySystemInformation';<br><br>procedure TForm1.btnSysInfoClick(Sender: TObject);<br>var<br> SysProcessInfo: PTSYSTEM_PROCESSES;<br> status: Longint; {long}<br> temp, Index, numBytes, numEntries: DWORD;<br> buf: TPDword;<br>begin<br> NtQuerySystemInformation(PROCESS_INFORMATION,<br> @temp, 0, @numBytes);<br><br> buf := AllocMem(numBytes * 2);<br><br> status := NtQuerySystemInformation(PROCESS_INFORMATION,<br> Buf, numBytes *2 , @numBytes);<br> if status <> 0 then<br> begin<br> ShowOsError(Status);<br> end;<br>end;<br>