System Information API
Retrieve and manage information about the Windows operating system and hardware.
Introduction
The Windows API provides a comprehensive set of functions for querying and retrieving detailed information about the system's hardware, software, and operational status. This information is crucial for applications that need to adapt to different environments, optimize performance, or diagnose issues.
This section covers the primary APIs for accessing system-wide data, including:
- Operating system version and configuration
- Processor details
- Memory usage and availability
- Disk drive information
- Network adapter status
- User and system environment variables
Key APIs
GetVersionEx()
Retrieves detailed version information about the currently running operating system.
Header: windows.h
Syntax: BOOL GetVersionEx(LPSYSTEM_INFO lpSystemInfo);
Description: Populates a SYSTEM_INFO structure with information such as the platform ID, major and minor version numbers, processor type, and number of processors.
Example Usage:
#include <windows.h>
#include <iostream>
int main() {
SYSTEM_INFO sysInfo;
GetVersionEx(&sysInfo);
std::cout << "OS Version: " << sysInfo.dwMajorVersion << "." << sysInfo.dwMinorVersion << std::endl;
std::cout << "Processor Type: " << sysInfo.dwProcessorType << std::endl;
// ... more information
return 0;
}
GlobalMemoryStatusEx()
Retrieves the current memory status for the system.
Header: windows.h
Syntax: BOOL GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer);
Description: Populates a MEMORYSTATUSEX structure with information about total and available physical memory, total and available virtual memory, and page file usage.
Example Usage:
#include <windows.h>
#include <iostream>
int main() {
MEMORYSTATUSEX memInfo;
memInfo.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memInfo);
std::cout << "Total Physical Memory: " << memInfo.ullTotalPhys / (1024 * 1024) << " MB" << std::endl;
std::cout << "Available Physical Memory: " << memInfo.ullAvailPhys / (1024 * 1024) << " MB" << std::endl;
// ... more information
return 0;
}
GetComputerName()
Retrieves the name of the current computer.
Header: windows.h
Syntax: BOOL GetComputerName(LPTSTR lpBuffer, LPDWORD nSize);
Description: Stores the null-terminated string of the computer name in the buffer pointed to by lpBuffer. The size of the buffer (in characters) must be specified by nSize.
GetUserName()
Retrieves the name of the user currently logged onto the system.
Header: windows.h
Syntax: BOOL GetUserName(LPTSTR lpBuffer, LPDWORD pcbBuffer);
Description: Stores the null-terminated string of the user name in the buffer pointed to by lpBuffer. The size of the buffer (in characters) must be specified by pcbBuffer.
Additional Resources
For more in-depth information and advanced system information retrieval, explore the following: