Click to See Complete Forum and Search --> : How to get informations about hardware ?
lindpessoa
December 18th, 2004, 09:23 AM
I need informations of hardware for example (size of HD, size of memory, OS, ...). How can I get these informations using c++ language ? Are there any website with examples that help me to solve my problem ?
Thanks,
Lindeberg
Paul Rice
December 18th, 2004, 09:32 AM
I need informations of hardware for example (size of HD, size of memory, OS, ...). How can I get these informations using c++ language ? Are there any website with examples that help me to solve my problem ?
Thanks,
Lindeberg
It's probably not going to help you with everything, but you can try DeviceIoControl() for at least some hardware info.
NoHero
December 18th, 2004, 09:33 AM
There are some function than can help you with several queries:
* GetSystemInfo (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsysteminfo.asp) : Helps you to get extended information like page size, physical start address and so on.
* GetVersionEx (http://msdn.microsoft.com/library/en-us/sysinfo/base/getversionex.asp) Returns the version numbers of the Operating System you are running on.
* IsProcessorFeaturePresent (http://msdn.microsoft.com/library/en-us/sysinfo/base/isprocessorfeaturepresent.asp?) Helps you to determinate if specified processor features are available. Like MMX, SDE and so on.
* SystemParametersInfo (http://msdn.microsoft.com/library/en-us/sysinfo/base/systemparametersinfo.asp) Helps you to configure the windows environment. For example retrieves and/or sets the current screensaver.
* GlobalMemoryStatus (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalmemorystatus.asp) To retrieve memory info: How much bytes physical memory is available? And so on.
* GetVolumeInformation (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/getvolumeinformation.asp) Basic volume information such as volume label and checks for several features enabled or not.
* GetDiskFreeSpace (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/getdiskfreespace.asp) Returns the bytes that are available on a specified drive.
Hope this helps!
Andreas Masur
December 18th, 2004, 03:11 PM
And to provide several examples...
#include <iostream>
#include <windows.h>
#include <memory.h>
#include <conio.h>
int main()
{
MEMORYSTATUS MemStat;
// Zero structure
memset(&MemStat, 0, sizeof(MemStat));
// Get RAM snapshot
::GlobalMemoryStatus(&MemStat);
// Print results
std::cout << "Length of structure: " << MemStat.dwLength
<< std::endl
<< "Memory usage: " << MemStat.dwMemoryLoad
<< " %" << std::endl
<< "Physical memory: " << MemStat.dwTotalPhys / 1024
<< " KB" << std::endl
<< "Free physical memory: " << MemStat.dwAvailPhys / 1024
<< " KB" << std::endl
<< "Paging file: " << MemStat.dwTotalPageFile / 1024
<< " KB" << std::endl
<< "Free paging file: " << MemStat.dwAvailPageFile / 1024
<< " KB" << std::endl
<< "Virtual memory: " << MemStat.dwTotalVirtual / 1024
<< " KB" << std::endl
<< "Free virtual memory: " << MemStat.dwAvailVirtual / 1024
<< " KB" << std::endl;
// Wait for keystroke
_getch();
return 0;
}
Andreas Masur
December 18th, 2004, 03:11 PM
To get information about the memory usage of a process you can use the function 'GetProcessMemoryInfo()'...
#include <iostream>
#include <iomanip>
#include <psapi.h>
// Add 'psapi.lib' to your linker options
int main()
{
// Open current process
HANDLE hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ::GetCurrentProcessId());
if(hProcess)
{
PROCESS_MEMORY_COUNTERS ProcessMemoryCounters;
memset(&ProcessMemoryCounters, 0, sizeof(ProcessMemoryCounters));
// Set size of structure
ProcessMemoryCounters.cb = sizeof(ProcessMemoryCounters);
// Get memory usage
if(::GetProcessMemoryInfo(hProcess,
&ProcessMemoryCounters,
sizeof(ProcessMemoryCounters)) == TRUE)
{
std::cout << std::setfill('0') << std::hex
<< "PageFaultCount: 0x" << std::setw(8)
<< ProcessMemoryCounters.PageFaultCount << std::endl
<< "PeakWorkingSetSize: 0x" << std::setw(8)
<< ProcessMemoryCounters.PeakWorkingSetSize << std::endl
<< "WorkingSetSize: 0x" << std::setw(8)
<< ProcessMemoryCounters.WorkingSetSize << std::endl
<< "QuotaPeakPagedPoolUsage: 0x" << std::setw(8)
<< ProcessMemoryCounters.QuotaPeakPagedPoolUsage << std::endl
<< "QuotaPagedPoolUsage: 0x" << std::setw(8)
<< ProcessMemoryCounters.QuotaPagedPoolUsage << std::endl
<< "QuotaPeakNonPagedPoolUsage: 0x" << std::setw(8)
<< ProcessMemoryCounters.QuotaPeakNonPagedPoolUsage << std::endl
<< "QuotaNonPagedPoolUsage: 0x" << std::setw(8)
<< ProcessMemoryCounters.QuotaNonPagedPoolUsage << std::endl
<< "PagefileUsage: 0x" << std::setw(8)
<< ProcessMemoryCounters.PagefileUsage << std::endl
<< "PeakPagefileUsage: 0x" << std::setw(8)
<< ProcessMemoryCounters.PeakPagefileUsage <<std::endl;
}
else
std::cout << "Could not get memory usage (Error: "
<< ::GetLastError() << ")" << std::endl;
// Close process
::CloseHandle(hProcess);
}
else
std::cout << "Could not open process (Error "
<< ::GetLastError() << ")" << std::endl;
return 0;
}
Andreas Masur
December 18th, 2004, 03:12 PM
#include <windows.h>
OSVERSIONINFO OSInfo;
memset(&OSInfo, 0, sizeof(OSInfo));
// Set size
OSInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(::GetVersionEx((OSVERSIONINFO *) &OSInfo) == FALSE)
return false;
switch(OSInfo.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:
if(OSInfo.dwMajorVersion <= 4)
// Microsoft Windows NT
if((OSInfo.dwMajorVersion == 5) && (!OSInfo.dwMinorVersion))
// Microsoft Windows 2000
if((OSInfo.dwMajorVersion == 5) && (OSInfo.dwMinorVersion == 1))
// Microsoft Windows XP
break;
case VER_PLATFORM_WIN32_WINDOWS:
if((OSInfo.dwMajorVersion == 4) && (!OSInfo.dwMinorVersion))
if(OSInfo.szCSDVersion[1] == 'C')
// Microsoft Windows 95 OSR2
else
// Microsoft Windows 95
if((OSInfo.dwMajorVersion == 4) && (OSInfo.dwMinorVersion == 10))
if(OSInfo.szCSDVersion[1] == 'A')
// Microsoft Windows 98 SE
else
// Microsoft Windows 98
if((OSInfo.dwMajorVersion == 4) && (OSInfo.dwMinorVersion == 90))
// Microsoft Windows ME
break;
case VER_PLATFORM_WIN32s:
// Microsoft Win32s
break;
}
You can also take a look at this article (http://www.codeproject.com/system/dtwinver.asp). This is one of the most comprehensive tool
for OS detection I saw...
Andreas Masur
December 18th, 2004, 03:16 PM
FAQs:
How to get information about a partition? (http://www.codeguru.com/forum/showthread.php?t=312464)
How to get the available logical partitions on my PC? (http://www.codeguru.com/forum/showthread.php?t=312465)
How can I check the free space on a partition? (http://www.codeguru.com/forum/showthread.php?t=312466)
Andreas Masur
December 18th, 2004, 03:21 PM
As a side note...all of the above could have been found by simply searching the forums... :cool:
SoftLock
April 19th, 2005, 12:00 PM
How can we read the serial number of RAM?
SoftLock
April 19th, 2005, 12:21 PM
How is GUID created??
Siddhartha
April 19th, 2005, 02:46 PM
How is GUID created??
GUIDs i.e. Globally Unique Identifiers like this one -
{74E1B2DE-D93E-49f6-B019-10DB9D727846}
are 38-character long identifiers that are (usually) composed using -
1. Network adapter MAC address (this is unique)
2. Time of creation.
3. A random number.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.