System Information API Reference

This section provides information about Windows APIs for retrieving and managing system-level information. This includes details about the operating system, hardware, processes, and other system-wide data.

Operating System Information

APIs to get details about the Windows version, build number, architecture, and other OS-specific properties.

GetVersionEx

BOOL GetVersionEx(LPOSVERSIONINFO lpVersionInformation);

Retrieves detailed information about the current version of the installed operating system.

Parameters:

lpVersionInformation: A pointer to an OSVERSIONINFO structure that receives the version information.

Return Value:

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Call GetLastError for extended error information.


// Example usage:
OSVERSIONINFO osver;
ZeroMemory(&osver, sizeof(OSVERSIONINFO));
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osver);
// osver now contains version details
            

GetSystemInfo

VOID GetSystemInfo(LPSYSTEM_INFO lpSystemInfo);

Retrieves information about the current system, including processor architecture, page size, and active processor count.

Parameters:

lpSystemInfo: A pointer to a SYSTEM_INFO structure that receives general information about the current system.

Return Value:

This function does not return a value.

OSVERSIONINFO Structure

Provides detailed version information about the operating system.

Member Type Description
dwOSVersionInfoSize DWORD The size of this structure, in bytes.
dwMajorVersion DWORD The major version number of the operating system.
dwMinorVersion DWORD The minor version number of the operating system.
dwBuildNumber DWORD The build number of the operating system.
dwPlatformId DWORD The operating system platform.
szCSDVersion TCHAR[128] A null-terminated string that specifies the Service Pack version (e.g., "Service Pack 1").

SYSTEM_INFO Structure

Contains information about the current computer system.

Member Type Description
wProcessorArchitecture WORD The processor architecture of the installed operating system.
wReserved WORD Reserved; must be zero.
dwPageSize DWORD The allocation granularity for the virtual memory.
lpMaximumApplicationAddress LPVOID A pointer to the maximum address of the process available to the application.
dwActiveProcessorMask DWORD_PTR A bitmask representing the set of active logical processors in the current system.
dwNumberOfProcessors DWORD The number of logical processors available on the current system.
dwProcessorType DWORD An identifier for the type of processor on the current machine.
dwAllocationGranularity DWORD The granularity of the processor's cache, in bytes.

Hardware Information

APIs to query details about CPU, memory, disks, and other hardware components.

GetLogicalProcessorInformation

BOOL GetLogicalProcessorInformation(PSYSLOGICALPROCESSORINFORMATION Buffer, PDWORD ReturnedLength);

Retrieves information about the logical processors configured on the system, including cache information, interrupts, and NUMA topology.

Parameters:

Buffer: A pointer to a buffer that receives a null-terminated array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION structures.

ReturnedLength: A pointer to a DWORD that, on input, specifies the size of the buffer pointed to by Buffer, in bytes. If the function returns FALSE and GetLastError returns ERROR_INSUFFICIENT_BUFFER, this parameter is set to the minimum buffer size required.

Return Value:

If the function succeeds, it returns TRUE. If the function fails, it returns FALSE.

SYSTEM_LOGICAL_PROCESSOR_INFORMATION Structure

Used by the GetLogicalProcessorInformation function to provide information about logical processors.

Member Type Description
ProcessorMask PROCESSOR_NUMBER A mask indicating the logical processors that are part of this group.
Relationship LOGICAL_PROCESSOR_RELATIONSHIP The relationship between the processors.
Cache CACHE_DESCRIPTOR Cache information. Valid if Relationship is RelationCache.
ProcessorExtent PROCESSOR_RELATIONSHIP Processor extension information.
NumaNode NUMA_NODE_RELATIONSHIP NUMA node information.

Process and Thread Information

APIs for managing and querying information about running processes and threads.

EnumProcesses

BOOL EnumProcesses(DWORD* pProcessIds, DWORD cb, DWORD* pBytesReturned);

Retrieves a list of process identifiers for the processes that are currently running on the local computer.

Parameters:

pProcessIds: A pointer to an array that receives a list of process identifiers.

cb: The size of the array pointed to by pProcessIds, in bytes.

pBytesReturned: A pointer to a variable that receives the number of bytes returned in the array.

Return Value:

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.

GetProcessMemoryInfo

BOOL GetProcessMemoryInfo(HANDLE hProcess, PPROCESS_MEMORY_COUNTERS pPsme, DWORD cb);

Retrieves information about the memory usage of the specified process.

Parameters:

hProcess: A handle to the process.

pPsme: A pointer to a PROCESS_MEMORY_COUNTERS structure that receives memory usage information.

cb: The size of the PROCESS_MEMORY_COUNTERS structure, in bytes.

Return Value:

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.

PROCESS_MEMORY_COUNTERS Structure

Contains memory statistics for a process.

Member Type Description
cb DWORD The size of the structure, in bytes.
PageFaultCount DWORD The number of page faults.
PeakWorkingSetSize SIZE_T The maximum number of bytes the process has ever held in its working set.
WorkingSetSize SIZE_T The current number of bytes in the process's working set.
QuotaPeakNonPagedPoolUsage SIZE_T The maximum number of nonpaged pool bytes the process has ever used.
QuotaNonPagedPoolUsage SIZE_T The current number of bytes of nonpaged pool that the process has used.
QuotaPeakPagedPoolUsage SIZE_T The maximum number of paged pool bytes the process has ever used.
QuotaPagedPoolUsage SIZE_T The current number of bytes of paged pool that the process has used.
Reserved SIZE_T Reserved.
PrivateUsage SIZE_T The current number of bytes this process has allocated for its private use.
TotalImageSize SIZE_T The size of the image file associated with the process.
TlsAccessedPages SIZE_T The number of pages that have been accessed by the thread-local storage (TLS) allocaions for this process.

System Performance Counters

APIs for accessing system performance data, such as CPU utilization and disk I/O.

PdhAddCounter

PDH_STATUS PdhAddCounter(PDH_HQUERY hQuery, LPCTSTR szCounterPath, DWORD_PTR dwUserData, PDH_HCOUNTER* phCounter);

Adds a counter to the specified query.

Parameters:

hQuery: Handle to the query to which the counter is to be added.

szCounterPath: Null-terminated string specifying the full path of the counter to add.

dwUserData: User-defined value.

phCounter: Pointer to a handle.

Return Value:

Returns ERROR_SUCCESS if the function succeeds. If the function fails, the return value is a system error code.

Note: The Performance Data Helper (PDH) library provides a more robust way to access performance counters.