328 lines
7.7 KiB
C++
328 lines
7.7 KiB
C++
|
|
#define _WIN32_WINNT 0x0500
|
|
#include <windows.h>
|
|
#include <Wbemidl.h>
|
|
#include <comdef.h>
|
|
#include "SCENE.H"
|
|
#include <string>
|
|
#include "http_client_curl.h"
|
|
char MacAddress [24];
|
|
/*
|
|
#define ConsoleNumberOfdLines 40
|
|
static char Console[ConsoleNumberOfdLines*80];
|
|
|
|
void OutputConsole(char *String)
|
|
{
|
|
memmove(Console + 80,Console,(ConsoleNumberOfdLines-1)*80);
|
|
sprintf(Console,"%s",String);
|
|
}
|
|
|
|
void DrawConsole(u32 *Image,u32 SX,u32 SY)
|
|
{
|
|
for ( u32 Counter = 0 ; Counter < ConsoleNumberOfdLines ; Counter++)
|
|
{
|
|
//DRawTEXT_Soft_B((unsigned char *)(Console + 80 * Counter),(u32*)Image,10, Counter * 17, SX , SY , 0xffff00);
|
|
}
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
int RequestWMIInfo(BSTR strQuery, BSTR strData, char *bufferResult)
|
|
{
|
|
CoInitialize(NULL);
|
|
|
|
//Security needs to be initialized in XP first
|
|
|
|
static bool securityInitialized = false; // CoInitializeSecurity() only succeeds once per process
|
|
if (!securityInitialized)
|
|
{
|
|
securityInitialized = true;
|
|
if(CoInitializeSecurity( NULL,
|
|
-1,
|
|
NULL,
|
|
NULL,
|
|
RPC_C_AUTHN_LEVEL_PKT,
|
|
RPC_C_IMP_LEVEL_IMPERSONATE,
|
|
NULL,
|
|
EOAC_NONE,
|
|
0
|
|
) != S_OK)
|
|
{
|
|
CoUninitialize();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
IWbemLocator * pIWbemLocator = NULL;
|
|
IWbemServices * pWbemServices = NULL;
|
|
IEnumWbemClassObject * pEnumObject = NULL;
|
|
BSTR bstrNamespace = (L"root\\cimv2");
|
|
HRESULT hRes = CoCreateInstance (
|
|
CLSID_WbemAdministrativeLocator,
|
|
NULL ,
|
|
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
|
|
IID_IUnknown ,
|
|
( void ** ) & pIWbemLocator
|
|
) ;
|
|
if (SUCCEEDED(hRes))
|
|
{
|
|
hRes = pIWbemLocator->ConnectServer(
|
|
bstrNamespace, // Namespace
|
|
NULL, // Userid
|
|
NULL, // PW
|
|
NULL, // Locale
|
|
0, // flags
|
|
NULL, // Authority
|
|
NULL, // Context
|
|
&pWbemServices
|
|
);
|
|
}
|
|
BSTR strQL = (L"WQL");
|
|
hRes = pWbemServices->ExecQuery(strQL, strQuery,
|
|
WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
|
|
|
|
if (!SUCCEEDED(hRes) || !pEnumObject)
|
|
{
|
|
pIWbemLocator->Release();
|
|
pWbemServices->Release();
|
|
return 0;
|
|
}
|
|
|
|
ULONG uCount = 1, uReturned;
|
|
IWbemClassObject * pClassObject = NULL;
|
|
hRes = pEnumObject->Reset();
|
|
hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
|
|
|
|
if (!SUCCEEDED(hRes) || !pClassObject)
|
|
{
|
|
pIWbemLocator->Release();
|
|
pWbemServices->Release();
|
|
pEnumObject->Release();
|
|
return 0;
|
|
}
|
|
|
|
LPSAFEARRAY psa = NULL;
|
|
hRes = pClassObject->GetNames(NULL, 0, NULL, &psa);
|
|
|
|
VARIANT v;
|
|
BSTR strClassProp = SysAllocString(strData);
|
|
hRes = pClassObject->Get(strClassProp, 0, &v, 0, 0);
|
|
SysFreeString(strClassProp);
|
|
|
|
int result = SUCCEEDED(hRes);
|
|
if (v.vt != 1)
|
|
{
|
|
_bstr_t bstrPath = &v; //Just to convert BSTR to ANSI
|
|
char* strPath=(char*)bstrPath;
|
|
if (result)
|
|
strcpy(bufferResult, strPath);
|
|
VariantClear( &v );
|
|
} else
|
|
{
|
|
*bufferResult = 0;
|
|
}
|
|
pIWbemLocator->Release();
|
|
pWbemServices->Release();
|
|
pEnumObject->Release();
|
|
pClassObject->Release();
|
|
CoUninitialize();
|
|
return result;
|
|
}
|
|
|
|
|
|
// Warning, Must Be call after init ... Must be called from the main thread.
|
|
std::string GetHardwareData(bool useUrlFormat=false, CHttpClient *httpClient=NULL)
|
|
{
|
|
// GetSystemInfo
|
|
// GetSystemMetrics
|
|
// SystemParametersInfo
|
|
// CPUID
|
|
|
|
// Get RAM
|
|
char buffer[1024] = "";
|
|
char strMemory[1024] = "";
|
|
char strProcessor[1024] = "";
|
|
char strVideoCard[1024] = "";
|
|
char strVideoCardRAM[1024] = "";
|
|
char strVideoCardResolution[1024] = "";
|
|
char strVideoCardDriver[1024] = "";
|
|
char strAudioCard[1024] = "";
|
|
char strOS[1024] = "";
|
|
char strWebcam[1024] = "";
|
|
char strSID[1024] = "";
|
|
|
|
MEMORYSTATUSEX memoryStatus;
|
|
memset(&memoryStatus, 0, sizeof(memoryStatus));
|
|
memoryStatus.dwLength = sizeof(memoryStatus);
|
|
|
|
if (GlobalMemoryStatusEx(&memoryStatus))
|
|
{
|
|
if (useUrlFormat)
|
|
sprintf(strMemory, "%d", memoryStatus.ullTotalPhys >> 20);
|
|
else
|
|
sprintf(strMemory, "RAM: %dMB", memoryStatus.ullTotalPhys >> 20);
|
|
}
|
|
|
|
if (RequestWMIInfo(L"Select * from Win32_Processor", L"Name", buffer)) // "ProcessorID
|
|
{
|
|
if (useUrlFormat)
|
|
{
|
|
#ifdef ONLINE_MODE
|
|
UEString ue(buffer, true, httpClient);
|
|
sprintf(strProcessor, "%s", ue.c_str());
|
|
#else
|
|
sprintf(strProcessor, "%s", buffer);
|
|
#endif
|
|
}
|
|
else
|
|
sprintf(strProcessor, "Processor: %s", buffer);
|
|
}
|
|
|
|
//if (RequestWMIInfo(L"Select * from Win32_SystemEnclosure", L"SerialNumber", buffer))
|
|
// sprintf(strSID, "SID: %s", buffer);
|
|
|
|
if (RequestWMIInfo(L"Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE", L"MACAddress", buffer))
|
|
{
|
|
if (useUrlFormat)
|
|
{
|
|
#ifdef ONLINE_MODE
|
|
UEString ue(buffer, true, httpClient);
|
|
sprintf(strSID, "%s", ue.c_str());
|
|
#else
|
|
sprintf(strSID, "%s", buffer);
|
|
#endif
|
|
}
|
|
else
|
|
sprintf(strSID, "MAC Address: %s", buffer);
|
|
strncpy(MacAddress, buffer, 23);
|
|
}
|
|
|
|
|
|
if (RequestWMIInfo(L"Select * from Win32_VideoController", L"Name", buffer))
|
|
{
|
|
if (useUrlFormat)
|
|
{
|
|
#ifdef ONLINE_MODE
|
|
UEString ue(buffer, true, httpClient);
|
|
sprintf(strVideoCard, "%s", ue.c_str());
|
|
#else
|
|
sprintf(strVideoCard, "%s", buffer);
|
|
#endif
|
|
}
|
|
else
|
|
sprintf(strVideoCard, "Video Card: %s", buffer);
|
|
}
|
|
if (RequestWMIInfo(L"Select * from Win32_VideoController", L"AdapterRAM", buffer))
|
|
{
|
|
if (useUrlFormat)
|
|
sprintf(strVideoCardRAM, "%d", atoi(buffer)>>20);
|
|
else
|
|
sprintf(strVideoCardRAM, "Video Card RAM: %dMo", atoi(buffer)>>20);
|
|
}
|
|
|
|
if (RequestWMIInfo(L"Select * from Win32_VideoController", L"VideoModeDescription", buffer))
|
|
{
|
|
if (useUrlFormat)
|
|
{
|
|
#ifdef ONLINE_MODE
|
|
UEString ue(buffer, true, httpClient);
|
|
sprintf(strVideoCardResolution, "%s", ue.c_str());
|
|
#else
|
|
sprintf(strVideoCardResolution, "%s", buffer);
|
|
#endif
|
|
}
|
|
else
|
|
sprintf(strVideoCardResolution, "Video Card Description: %s", buffer);
|
|
}
|
|
|
|
if (RequestWMIInfo(L"Select * from Win32_VideoController", L"InstalledDisplayDrivers", buffer))
|
|
{
|
|
if (useUrlFormat)
|
|
{
|
|
#ifdef ONLINE_MODE
|
|
UEString ue(buffer, true, httpClient);
|
|
sprintf(strVideoCardDriver, "%s", ue.c_str());
|
|
#else
|
|
sprintf(strVideoCardDriver, "%s", buffer);
|
|
#endif
|
|
}
|
|
else
|
|
sprintf(strVideoCardDriver, "Video Card Driver: %s", buffer);
|
|
}
|
|
if (RequestWMIInfo(L"Select * from Win32_VideoController", L"DriverVersion", buffer))
|
|
{
|
|
if (useUrlFormat)
|
|
{
|
|
#ifdef ONLINE_MODE
|
|
UEString ue(buffer, true, httpClient);
|
|
sprintf(strVideoCardDriver + strlen(strVideoCardDriver), " ver %s", ue.c_str());
|
|
#else
|
|
sprintf(strVideoCardDriver + strlen(strVideoCardDriver), "%s", buffer);
|
|
#endif
|
|
}
|
|
else
|
|
sprintf(strVideoCardDriver + strlen(strVideoCardDriver), " version %s", buffer);
|
|
}
|
|
|
|
if (RequestWMIInfo(L"Select * from Win32_SoundDevice", L"ProductName", buffer))
|
|
{
|
|
if (useUrlFormat)
|
|
{
|
|
#ifdef ONLINE_MODE
|
|
UEString ue(buffer, true, httpClient);
|
|
sprintf(strAudioCard, "%s", ue.c_str());
|
|
#else
|
|
sprintf(strAudioCard, "%s", buffer);
|
|
#endif
|
|
}
|
|
else
|
|
sprintf(strAudioCard, "Audio Card Driver: %s", buffer);
|
|
}
|
|
|
|
if (RequestWMIInfo(L"Select Name from Win32_OperatingSystem", L"Name", buffer))
|
|
{
|
|
if (useUrlFormat)
|
|
{
|
|
#ifdef ONLINE_MODE
|
|
UEString ue(buffer, true, httpClient);
|
|
sprintf(strOS, "%s", ue.c_str());
|
|
#else
|
|
sprintf(strOS, "%s", buffer);
|
|
#endif
|
|
}
|
|
else
|
|
sprintf(strOS, "OS: %s", buffer);
|
|
}
|
|
|
|
extern TCHAR CurrWebCam[256];
|
|
if (useUrlFormat)
|
|
{
|
|
#ifdef ONLINE_MODE
|
|
UEString ue(CurrWebCam, true, httpClient);
|
|
sprintf(strWebcam, "%s", ue.c_str());
|
|
#else
|
|
sprintf(strWebcam, "%s", CurrWebCam);
|
|
#endif
|
|
}
|
|
else
|
|
sprintf(strWebcam, "Webcam: %s", CurrWebCam);
|
|
|
|
|
|
std::string hardwareStr = std::string(strProcessor) + "," + strMemory + "," +
|
|
strVideoCard + "," + strVideoCardRAM + "," + strVideoCardResolution + "," + strVideoCardDriver + "," +
|
|
strAudioCard + "," + strWebcam + "," + strOS + ","; // don't fetch MAC and SID
|
|
|
|
|
|
// Set Info specific on Hardware
|
|
strlwr(strVideoCard);
|
|
if (strstr(strVideoCard, "intel"))
|
|
{
|
|
extern int D3DDisplay;
|
|
if (D3DDisplay < 0) D3DDisplay = -2;
|
|
extern int SoftCopyTime;
|
|
SoftCopyTime = timeGetTime() + 15000;
|
|
}
|
|
|
|
return hardwareStr;
|
|
}
|