typedef struct _IO_COUNTERS
{
LARGE_INTEGER ReadOperationCount;
LARGE_INTEGER WriteOperationCount;
LARGE_INTEGER OtherOperationCount;
LARGE_INTEGER ReadTransferCount;
LARGE_INTEGER WriteTransferCount;
LARGE_INTEGER OtherTransferCount;
}IO_COUNTERS,*PIO_COUNTERS;
typedef enum _THREAD_STATE
{
StateInitialized,
StateReady,
StateRunning,
StateStandby,
StateTerminated,
StateWait,
StateTransition,
StateUnknown
}THREAD_STATE;
typedef enum _KWAIT_REASON
{
Executive,
FreePage,
PageIn,
PoolAllocation,
DelayExecution,
Suspended,
UserRequest,
WrExecutive,
WrFreePage,
WrPageIn,
WrPoolAllocation,
WrDelayExecution,
WrSuspended,
WrUserRequest,
WrEventPair,
WrQueue,
WrLpcReceive,
WrLpcReply,
WrVertualMemory,
WrPageOut,
WrRendezvous,
Spare2,
Spare3,
Spare4,
Spare5,
Spare6,
WrKernel
}KWAIT_REASON;
typedef struct _SYSTEM_THREADS
{
LARGE_INTEGER KernelTime;
LARGE_INTEGER UserTime;
LARGE_INTEGER CreateTime;
ULONG WaitTime;
PVOID StartAddress;
CLIENT_ID ClientId;
KPRIORITY Priority;
KPRIORITY BasePriority;
ULONG ContextSwitchCount;
THREAD_STATE; State;
KWAIT_REASON; WaitReason;
}SYSTEM_THREADS,*PSYSTEM_THREADS;
typedef struct _SYSTEM_PROCESSES
{
ULONG; NextEntryDelta;
ULONG; ThreadCount;
ULONG; Reserved1[6];
LARGE_INTEGER; CreateTime;
LARGE_INTEGER; UserTime;
LARGE_INTEGER; KernelTime;
UNICODE_STRING ProcessName;
KPRIORITY; BasePriority;
ULONG; ProcessId;
ULONG; InheritedFromProcessId;
ULONG; HandleCount;
ULONG; Reserved2[2];
VM_COUNTERSVmCounters;
IO_COUNTERSIoCounters;
SYSTEM_THREADS Threads[1];
}SYSTEM_PROCESSES,*PSYSTEM_PROCESSES;
typedef DWordSYSTEM_INFORMATION_CLASS;
typedef NTSTATUS (__stdcall *NTQUERYSYSTEMINFORMATION)
(IN SYSTEM_INFORMATION_CLASS,
IN OUT PVOID,
IN ULONG,
OUTPULONG OPTIONAL);
NTQUERYSYSTEMINFORMATION NtQuerySystemInformation;
DWORD EnumProcess()
{
PSYSTEM_PROCESSES; pSystemProc;
HMODULEhNtDll = NULL;
LPVOID lpSystemInfo= NULL;
DWORD; dwNumberBytes; = MAX_INFO_BUF_LEN;
DWORD; dwTotalProcess = 0;
DWORD; dwReturnLength;
NTSTATUSStatus;
LONGLONGllTempTime;
__try
{
hNtDll = LoadLibrary("NtDll.dll");
if(hNtDll == NULL)
{
printf("LoadLibrary Error: %dn",GetLastError());
__leave;
}
NtQuerySystemInformation = (NTQUERYSYSTEMINFORMATION)GetProCADdress(hNtDll,"NtQuerySystemInformation");
; if(NtQuerySystemInformation == NULL)
{
printf("GetProcAddress for NtQuerySystemInformation Error: %dn",GetLastError());
__leave;
}
lpSystemInfo = (LPVOID)malloc(dwNumberBytes);
Status = NtQuerySystemInformation(NT_PROCESSTHREAD_INFO,
lpSystemInfo,
dwNumberBytes,
&dwReturnLength);
if(Status == STATUS_INFO_LENGTH_MISMATCH)
{
printf("STATUS_INFO_LENGTH_MISMATCHn");
__leave;
}
else if(Status != STATUS_SUCCESS)
{
printf("NtQuerySystemInformation Error: %dn",GetLastError());
__leave;
}
printf("%-20s%6s%7s%8s%6s%7s%7ssn","ProcessName","PID","PPID","WsSize","Prio.","Thread","Handle","CPU Time");
printf("--------------------------------------------------------------------------n");
pSystemProc = (PSYSTEM_PROCESSES)lpSystemInfo;
while(pSystemProc->NextEntryDelta != 0)
{
if(pSystemProc->ProcessId != 0)
{
wprintf(L"%-20s",pSystemProc->ProcessName.Buffer);
}
else
{
wprintf(L"%-20s",L"System Idle Process");
}
printf("m",pSystemProc->ProcessId);
printf("}",pSystemProc->InheritedFromProcessId);
printf("}K",pSystemProc->VmCounters.WorkingSetSize/1024);
printf("m",pSystemProc->BasePriority);
printf("}",pSystemProc->ThreadCount);
printf("}",pSystemProc->HandleCount);
llTempTime; = pSystemProc->KernelTime.QuadPartpSystemProc->UserTime.QuadPart;
推荐阅读
- Windows2003 远程桌面超过最大连接数解决办法
- win2003 sql 1433 端口连接问题
- Windows 2003系统加速十四招大法
- 为Windows 2003加装视频压缩
- Win 2003系统网络负载均衡的实现
- Windows 2003优化配置
- 变Win 2003为工作站
- 配置基于Win 2003 的服务器
- Win2003下提高FSO的安全性
- Win 2003系统十例最新配置技巧
