Hi,
Im looking into some struct array work with WMI for multiple devices, such as CPU, memory, hard drive etc... and i've come accross a bridge i can't seem to cross...
Basically im using WMI and querying "Win32_LogicalDisk" to gather freespace, size, etc... and backing this up to an array. The problem i have is with my SmartStatus. The Status in "Win32_LogicalDisk" is blank, so i can't query this here. The Status in "Win32_DiskDrive" however is not blank, but doesn't contain drive letters or free space. So i do need to query both.
What i need to do is add the result i get from the query on "Win32_DiskDrive"->"Status" to the data in array.
Im bad at explaining but the first query will add to the array like so:
3
C:
<- BLANK
19658754
11235
60%
Second query will find "Status" and i need to add it to the above Blank area, so when i print the result its all there.
CODE:
struct DriveInfo
{
int nType;
char DriveLetter[10];
char SmartStatus[50];
float TotalSpace;
float FreeSpace;
float PercentFree;
};
vector< ServiceInfo* > ServiceList;
ServiceInfo *FoundService = NULL;
vector< DriveInfo* > DriveList;
DriveInfo *FoundDrive = NULL;
UINT ContinueCommands( CXenoClientDlg *pThis )
{
char pBuffer[100];
int StatusInfo;
FoundService = new ServiceInfo( );
FoundDrive = new DriveInfo( );
while( true )
{
if( App.LoggedIn )
{
CWMIReader *Services = new CWMIReader( );
if( !Services->Initialized ) { Services->Initialized = Services->Setup( ); }
if( Services->Initialized )
{
if( Services->GetFirstDevice( L"Win32_Service" ) )
{
Services->ReadPropertyString( L"DisplayName", FoundService->Name );
Services->ReadPropertyString( L"StartMode", FoundService->StartupType );
Services->ReadPropertyBool( L"Started", FoundService->Started );
if( !strcmp( FoundService->StartupType, "Auto" ) )
{
Tools.Log( "Service: [%s] - [%s] - [%s]", FoundService->Name, FoundService->StartupType, !strcmp( FoundService->Started, "1" ) ? "Started" : "Not Started" );
ServiceList.push_back( FoundService );
FoundService = new ServiceInfo;
ZeroMemory( FoundService, sizeof( ServiceInfo ) );
while( Services->GetNextDevice( ) )
{
Services->ReadPropertyString( L"DisplayName", FoundService->Name );
Services->ReadPropertyString( L"StartMode", FoundService->StartupType );
Services->ReadPropertyBool( L"Started", FoundService->Started );
if( !strcmp( FoundService->StartupType, "Auto" ) )
{
Tools.Log( "Service: [%s] - [%s] - [%s]", FoundService->Name, FoundService->StartupType, !strcmp( FoundService->Started, "1" ) ? "Started" : "Not Started" );
ServiceList.push_back( FoundService );
FoundService = new ServiceInfo;
ZeroMemory( FoundService, sizeof( ServiceInfo ) );
}
}
Services->EndQuery( );
}
}
if( Services->GetFirstDevice( L"Win32_LogicalDisk" ) )
{
Services->ReadPropertyInt( L"DriveType", pBuffer ); FoundDrive->nType = atoi( pBuffer );
if( FoundDrive->nType == 3 )
{
Services->ReadPropertyString( L"DeviceID", FoundDrive->DriveLetter );
Services->ReadPropertyString( L"Size", pBuffer ); FoundDrive->TotalSpace = atof( pBuffer )/1024.0f/1024.0f/1024.0f;
Services->ReadPropertyString( L"FreeSpace", pBuffer ); FoundDrive->FreeSpace = atof( pBuffer )/1024.0f/1024.0f/1024.0f;
FoundDrive->PercentFree = ( ( FoundDrive->FreeSpace / FoundDrive->TotalSpace ) * 100.0f );
DriveList.push_back( FoundDrive );
FoundDrive = new DriveInfo;
ZeroMemory( FoundDrive, sizeof( DriveInfo ) );
while( Services->GetNextDevice( ) )
{
Services->ReadPropertyInt( L"DriveType", pBuffer ); FoundDrive->nType = atoi( pBuffer );
if( FoundDrive->nType == 3 )
{
Services->ReadPropertyString( L"DeviceID", FoundDrive->DriveLetter );
Services->ReadPropertyString( L"Size", pBuffer ); FoundDrive->TotalSpace = atof( pBuffer )/1024.0f/1024.0f/1024.0f;
Services->ReadPropertyString( L"FreeSpace", pBuffer ); FoundDrive->FreeSpace = atof( pBuffer )/1024.0f/1024.0f/1024.0f;
FoundDrive->PercentFree = ( ( FoundDrive->FreeSpace / FoundDrive->TotalSpace ) * 100.0f );
DriveList.push_back( FoundDrive );
FoundDrive = new DriveInfo;
ZeroMemory( FoundDrive, sizeof( DriveInfo ) );
}
}
Services->EndQuery( );
}
}
if( Services->GetFirstDevice( L"Win32_DiskDrive" ) )
{
Services->ReadPropertyString( L"MediaType", pBuffer );
if( strstr( pBuffer, "Fixed" ) )
{
Services->ReadPropertyString( L"Status", FoundDrive->SmartStatus );
while( Services->GetNextDevice( ) )
{
Services->ReadPropertyString( L"MediaType", pBuffer );
if( strstr( pBuffer, "Fixed" ) )
{
Services->ReadPropertyString( L"Status", FoundDrive->SmartStatus );
}
}
Services->EndQuery( );
}
}
for( int i = 0; i < DriveList.size( ); ++i )
{
DriveInfo* CurrentDrive = DriveList.at( i );
Tools.Log( "Drive %s\\ has a status of \"%s\". %.0fGB Free Space, %.0fGB Total Space. %.0f%% Free Space", CurrentDrive->DriveLetter, CurrentDrive->SmartStatus, CurrentDrive->FreeSpace, CurrentDrive->TotalSpace, CurrentDrive->PercentFree );
}
}
ExitThread( 0 );
}
}
return 0;
}