Sign in to follow this  

Gathering System Specs

This topic is 4714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What I'm trying to do is gather as much information about a users machine as possible (using C++ and Windows). This includes geting the CPU speed, total ram, etc. I'm finding scattered information everywhere about it, but is there a tutorial on how to find lots of different specs on a users machine?

Share this post


Link to post
Share on other sites
This will help you out a bit with what you're looking for. AFAIK there's no way to get all that information from one call, I think you're out of luck for that. I'm not sure about getting the amount of RAM, but that should do for processor speed and type.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I believe you're looking for GlobalMemoryStatus(...);

Share this post


Link to post
Share on other sites
DxDiag can do that for you - Check the DxDiagReport sample that comes with the DX9 SDK, and the "DirectX Diagnostic Tool Reference" in the DirectX SDK documentation. It gathers EVERYTHING about the machine - OS version, language, RAM, ...etc (and even things like: IsNetMeetingRunning).

Share this post


Link to post
Share on other sites
Or you can use WMI. It contains all data about system which Windows has stored. DxDiag and similar tools probably use that too. It uses COM interface which is harder to get running, but usage is pretty easy. Once you are connected to wmi you can gather information directly from system. You can even connect to remote computer.

Here is example (it detects some properties of operating system):

#define _WIN32_DCOM
#include <iostream>
#include <comdef.h>
#include <Wbemidl.h>

using namespace std;

# pragma comment(lib, "wbemuuid.lib")

// output variant to wcout stream, bt is text written before value, at after value
void OutputVariant(char *bt, char *at, VARIANT var)
{
wcout << bt;

switch (var.vt)
{
case VT_EMPTY:
wcout << "No value" << endl;
break;

case VT_EMPTY | VT_BYREF:
wcout << "Invaid value" << endl;
break;

case VT_UI1:
wcout << (char) var.bVal << at;
break;

case VT_UI1 | VT_BYREF:
wcout << (char) *var.pbVal << at;
break;

case VT_UI2:
wcout << (unsigned __int16) var.uiVal << at;
break;

case VT_UI2 | VT_BYREF:
wcout << (unsigned __int16) *var.puiVal << at;
break;

case VT_UI4:
wcout << (unsigned __int32) var.ulVal << at;
break;

case VT_UI4 | VT_BYREF:
wcout << (unsigned __int32) *var.pulVal << at;
break;

case VT_UI8:
wcout << (unsigned __int64) var.ullVal << at;
break;

case VT_UI8 | VT_BYREF:
wcout << (unsigned __int64) *var.pullVal << at;
break;

case VT_UINT:
wcout << (unsigned int) var.uintVal << at;
break;

case VT_UINT | VT_BYREF:
wcout << (unsigned int) *var.puintVal << at;
break;

case VT_INT:
wcout << (int) var.intVal << at;
break;

case VT_INT | VT_BYREF:
wcout << (int) *var.puintVal << at;
break;

case VT_I1:
wcout << (char) var.cVal << at;
break;

case VT_I1 | VT_BYREF:
wcout << (char) *var.pcVal << at;
break;

case VT_I2:
wcout << (__int16) var.iVal << at;
break;

case VT_I2 | VT_BYREF:
wcout << (__int16) *var.piVal << at;
break;

case VT_I4:
wcout << (__int32) var.lVal << at;
break;

case VT_I4 | VT_BYREF:
wcout << (__int32) *var.plVal << at;
break;

case VT_I8:
wcout << (__int64) var.llVal << at;
break;

case VT_I8 | VT_BYREF:
wcout << (__int64) *var.pllVal << at;
break;

case VT_R4:
wcout << (float) var.fltVal << at;
break;

case VT_R4 | VT_BYREF:
wcout << (float) *var.pfltVal << at;
break;

case VT_R8:
wcout << (double) var.dblVal << at;
break;

case VT_R8 | VT_BYREF:
wcout << (double) *var.pdblVal << at;
break;

case VT_BSTR:
wcout << var.bstrVal << at;
break;

case VT_BSTR | VT_BYREF:
wcout << *var.pbstrVal << at;
break;

case VT_BOOL:
wcout << (var.boolVal == 0 ? "false" : "true") << at;
break;

case VT_BOOL | VT_BYREF:
wcout << (*var.pboolVal == 0 ? "false" : "true") << at;
break;

case VT_DATE:
{
unsigned short ddate;
unsigned short dtime;

if (VariantTimeToDosDateTime(var.date, &ddate, &dtime) != FALSE)
{
wcout << (ddate & 0x1F) << ". " << ((ddate & 0x1E0) >> 5) << ". " << (1980 + ((ddate & 0xFE00) >> 9)) << " "
<< ((dtime & 0xF800) >> 11) << ":" << ((dtime & 0x7E0) >> 5) << "." << 2 * (dtime & 0xF) << at;
}
else
{
wcout << "Ivalid date/time" << endl;
}
}
break;

case VT_DATE | VT_BYREF:
{
unsigned short ddate;
unsigned short dtime;

if (VariantTimeToDosDateTime(*var.pdate, &ddate, &dtime) != FALSE)
{
wcout << (ddate & 0x1F) << ". " << ((ddate & 0x1E0) >> 5) << ". " << (1980 + ((ddate & 0xFE00) >> 9)) << " "
<< ((dtime & 0xF800) >> 11) << ":" << ((dtime & 0x7E0) >> 5) << "." << 2 * (dtime & 0xF) << at;
}
else
{
wcout << "Ivalid date/time" << endl;
}
}
break;

default:
wcout << "Unsupported value type" << endl;
break;
}
}

int main(int argc, char **argv)
{
HRESULT hres;

// Initialize COM
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
cout << "Failed to initialize COM library. Error code = 0x" << hex << hres << endl;
return 1;
}

// Set general COM security levels
hres = CoInitializeSecurity(NULL, // Security descriptor
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL); // Reserved

if (FAILED(hres))
{
cout << "Failed to initialize security. Error code = 0x" << hex << hres << endl;
CoUninitialize();
return 2;
}

// Obtain the initial locator to WMI
IWbemLocator *Locator = NULL;

hres = CoCreateInstance(CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator,
(LPVOID *) &Locator);

if (FAILED(hres))
{
cout << "Failed to create IWbemLocator object." << " Err code = 0x" << hex << hres << endl;
CoUninitialize();
return 3;
}

// Connect to WMI through the IWbemLocator::ConnectServer method
IWbemServices *Services = NULL;

// Connect to the root\cimv2 namespace with the current user and obtain
// pointer to services to make IWbemServices calls.
hres = Locator->ConnectServer(_bstr_t(L"ROOT\\CIMV2"), // Connect to CIMV2 namespace of WMI
NULL, // User Name (NULL = curren user)
NULL, // User Password (NULL = current)
0, // Locale, current
NULL, // Security flags
0, // Authority
0, // Context object
&Services); // IWbemServices proxy


if (FAILED(hres))
{
cout << "Could not connect. Error code = 0x" << hex << hres << endl;
Locator->Release();
CoUninitialize();
return 4;
}

cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;

// Set security levels on the proxy
hres = CoSetProxyBlanket(Services, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE); // proxy capabilities

if (FAILED(hres))
{
cout << "Could not set proxy blanket. Error code = 0x" << hex << hres << endl;
Services->Release();
Locator->Release();
CoUninitialize();
return 5;
}

// get data from wmi
IEnumWbemClassObject *Enumerator[1] = {NULL};

// search for all objects with name Win32_OperatingSystem
hres = Services->ExecQuery(bstr_t("WQL"), // Query language, must be WQL
bstr_t("SELECT * FROM Win32_OperatingSystem"), // Query
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&Enumerator[0]); // Results

if (FAILED(hres))
{
cout << "Query for operating system name failed." << " Error code = 0x" << hex << hres << endl;
Services->Release();
Locator->Release();
CoUninitialize();
return 6;
}

// Get the data from the query
IWbemClassObject *SystemPropsObject;
ULONG Return = 0;

// we can have more objects (not likely for operating system,
// but for example for cpu there will be one object for each cpu)
while (Enumerator)
{
HRESULT hr = Enumerator[0]->Next(WBEM_INFINITE, 1, &SystemPropsObject, &Return);

if(Return == 0)
{
break;
}

VARIANT PropertyValue;
VariantInit(&PropertyValue);

// write some properties from class to output
hr = SystemPropsObject->Get(L"Name", 0, &PropertyValue, 0, 0);
OutputVariant("Name : ", "\n", PropertyValue);

hr = SystemPropsObject->Get(L"Caption", 0, &PropertyValue, 0, 0);
OutputVariant("Caption : ", "\n", PropertyValue);

hr = SystemPropsObject->Get(L"CSDVersion", 0, &PropertyValue, 0, 0);
OutputVariant("CSDVersion : ", "\n", PropertyValue);

hr = SystemPropsObject->Get(L"Manufacturer", 0, &PropertyValue, 0, 0);
OutputVariant("Manufacturer : ", "\n", PropertyValue);

hr = SystemPropsObject->Get(L"Version", 0, &PropertyValue, 0, 0);
OutputVariant("Version : ", "\n", PropertyValue);

hr = SystemPropsObject->Get(L"BuildNumber", 0, &PropertyValue, 0, 0);
OutputVariant("BuildNumber : ", "\n", PropertyValue);

hr = SystemPropsObject->Get(L"BuildType", 0, &PropertyValue, 0, 0);
OutputVariant("BuildType : ", "\n", PropertyValue);

hr = SystemPropsObject->Get(L"Distributed", 0, &PropertyValue, 0, 0);
OutputVariant("Distributed : ", "\n", PropertyValue);

hr = SystemPropsObject->Get(L"EncryptionLevel", 0, &PropertyValue, 0, 0);
OutputVariant("EncryptionLevel : ", " bits\n", PropertyValue);

hr = SystemPropsObject->Get(L"FreePhysicalMemory", 0, &PropertyValue, 0, 0);
OutputVariant("FreePhysicalMemory : ", " kB\n", PropertyValue);

hr = SystemPropsObject->Get(L"FreeVirtualMemory", 0, &PropertyValue, 0, 0);
OutputVariant("FreeVirtualMemory : ", " kB\n", PropertyValue);

hr = SystemPropsObject->Get(L"NumberOfProcesses", 0, &PropertyValue, 0, 0);
OutputVariant("NumberOfProcesses : ", "\n", PropertyValue);

VariantClear(&PropertyValue);
}

// Cleanup

Services->Release();
Locator->Release();
Enumerator[0]->Release();
SystemPropsObject->Release();
CoUninitialize();

getchar();
return 0;
}



More info about WMI classes can be found here.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
I believe you're looking for GlobalMemoryStatus(...);

This is correct if you want to know the amount of RAM. I'm working on this same thing right now. I've sent you a PM.

Share this post


Link to post
Share on other sites

This topic is 4714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this