Examine Information on Windows NT System Level Primitives

Environment: Windows NT 4.0/2000 only, VC6 SP4, NT DDK is not needed :)

Overview

This article presents two separate utilities (NtSysInfo and WhoUses) to examine low level information on such Windows NT system primitives such as processes, threads, windows, modules and objects. Some of the things that I'm doing here are similar to the utilities found on the sysinternals Web site.

NtSysInfo Syntax

NtSysInfo enables you to explore the Windows NT internals and enumerate the system's processes, windows, threads, objects.
Usage: NtSysInfo.exe [/H[type]|/M[dllname]|/P|/T|/W] [processId]}
 /H          Handle list. Can be filtered by "type"
             type: File, Thread, Semaphore, Process, Event,...
 /M          Module list. Can be filtered by "dllname"
 /P          Process list (processId not used)
 /T          Thread list
 /W          Window list
 processId   Process ID, dec. or 0x??? (-1 = every process, default)

Examples:
  NtSysInfo.exe /HFile 651
  NtSysInfo.exe /H 1248
  NtSysInfo.exe /Mkernel32.dll
  NtSysInfo.exe /P
  NtSysInfo.exe /W
  NtSysInfo.exe /W 1215

WhoUses Syntax

NtSysInfo allows you to list processes, windows, threads, objects. The WhoUses utility enalbes you to determine what process has a file or DLL locked.
Usage: WhoUses.exe [/M] fileName
  /M         fileName is a module name ( EXE, DLL, ... )
  fileName   File name

Examples:
  WhoUses.exe /M kernel32.dll
  WhoUses.exe /M c:\test\test.dll
  WhoUses.exe yourTextFile.txt
  WhoUses.exe c:\pagefile.sys
  WhoUses.exe Serial0

Code Examples

  1. Get the process list
  2. SystemProcessInformation pi;
    pi.Refresh();
    // Iterate through pi.m_ProcessInfos
    
  3. Get the thread list
  4. // processId == -1 means every process
    SystemThreadInformation ti( processId ); 
    ti.Refresh();
    // Iterate through ti.m_ThreadInfos
    
  5. Get the object list
  6. // processId == -1 means every process
    SystemHandleInformation oi( processId ); 
    oi.Refresh();
    // Iterate through oi.m_HandleInfos
    
  7. Get the file object list
  8. // processId == -1 means every process
    SystemHandleInformation fi( processId ); 
    fi.SetFilter( _T("File"), TRUE ); // Refresh
    // Iterate through fi.m_HandleInfos
    
  9. Get the window list
  10. // processId == -1 means every process
    SystemWindowInformation wi( processId ); 
    wi.Refresh();
    // Iterate through wi.m_WindowInfos
    
  11. Get window list
  12. // processId == -1 means every process
    SystemModuleInformation mi( processId ); 
    mi.Refresh();
    // Iterate through mi.m_ModuleInfos
    

Warnings & Disclaimers

This software uses a few undocumented functions (ntdll.dll), peeks around in your systems internals. Use at your own risk! It works for me. :)

Resources

  • Book: Undocumented Windows NT by Prasad Dabak, Sandeep Phadke, Milind Borate
  • Book: Windows NT/2000 Native API Reference by Gary Nebbett
  • Web: System Internals, www.sysinternals.com

Downloads

Download source/demo code - 38 Kb


Comments

  • Thanks

    Posted by Praveen on 08/15/2012 02:40am

    Hi, Excellent stuff!! thanks a lot Regards, Praveen

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: July 22, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT In this WhatWorks analysis, John Pescatore examines a use case where end users had local administrative rights on their PCs and it had gotten out of hand for this Fortune 500 Energy and Utilities company. The compelling event that prompted the company to reexamine this situation was the migration to Windows 7. In Windows XP, a custom tool that allowed users one of three levels of administrative rights to their workstations would need to be …

  • Mobile is introducing sweeping changes throughout your workplace. As a senior stakeholder driving mobile initiatives in your organization, you may be lost in a sea of technologies and claims from vendors promising rapid delivery of applications to your employees, customers, and partners. To help explain some of the topics you will need to be aware of, and to separate the must-haves from the nice-to-haves, this reference guide can help you with applying a mobile strategy in the context of application …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds