1

I have a project going where i need to gather information from a computer with graphic cards, from 1 up to 12, it has. This information is then saved in the cloud to be used later on.

What i need, to a minimun is:

What GPU it is How much memory Which PCI-slot it is using, 1, 2, 3 etc (or whatever name it is)

Windows WMI seems to have some information, and i have been looking through the different classes but it seems difficult to find the PCI-E slot. Do anyone know how to get this information?

Håkan
  • 31
  • 1
  • 2
  • why the down votes? yes the OP does not contain any code for his current attempt but I feel this is still relevant question. And down votes to a low rep user without any comments on what to change/repair or at least what is wrong are useless in my opinion. – Spektre Dec 17 '17 at 10:32

1 Answers1

1

You should look for PCI slot I do not see any PCI-E definitions in the strings (does not mean there are none). If I try just "PCI" the results enum both PCI and PCI-E devices. In BDS2006 C++/VCL I am using this (I busted some time ago) just by changing the match string:

//---------------------------------------------------------------------------
//$$---- Form CPP ----
//---------------------------------------------------------------------------
#include <vcl.h>
#include <setupapi.h>
#pragma hdrstop
#include "win_main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMain *Main;
//---------------------------------------------------------------------------
bool USBinfo()
    {
    int i,n;
    AnsiString s,txt="";
    DWORD dwSize,dwPropertyRegDataType;
    HDEVINFO hDevInfo;
    SP_DEVINFO_DATA DeviceInfoData;
    TCHAR szDesc[1024];

//  hDevInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_PRESENT|DIGCF_ALLCLASSES);           // List all devices
//  hDevInfo = SetupDiGetClassDevs(NULL, TEXT("USB"), NULL, DIGCF_PRESENT|DIGCF_ALLCLASSES);    // List all connected USB devices
    hDevInfo = SetupDiGetClassDevs(NULL, TEXT("PCI"), NULL, DIGCF_PRESENT|DIGCF_ALLCLASSES);    // List all connected PCI devices
    if (hDevInfo == INVALID_HANDLE_VALUE) return false;
    // Find the ones that are driverless
    for (i=0;;i++)
        {
        DeviceInfoData.cbSize = sizeof(DeviceInfoData);
        if (!SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData)) break;
        SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_DEVICEDESC,&dwPropertyRegDataType, (BYTE*)szDesc,sizeof(szDesc),&dwSize);
        s=szDesc; n=48; while (s.Length()<n) s+=" "; if (s.Length()>n) s=s.SubString(1,n); txt+=s+" ";
        SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_HARDWAREID,&dwPropertyRegDataType, (BYTE*)szDesc,sizeof(szDesc),&dwSize);
        s=szDesc; n=64; while (s.Length()<n) s+=" "; if (s.Length()>n) s=s.SubString(1,n); txt+=s+" ";
        SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_LOCATION_INFORMATION,&dwPropertyRegDataType, (BYTE*)szDesc,sizeof(szDesc),&dwSize);
        s=szDesc; n=40; while (s.Length()<n) s+=" "; if (s.Length()>n) s=s.SubString(1,n); txt+=s+" ";
        txt+="\r\n";
        }
    Main->mm_log->Lines->Add(txt);
    return true;
    }
//-------------------------------------------------------------------------
__fastcall TMain::TMain(TComponent* Owner) : TForm(Owner)
    {
    USBinfo();
    }
//-------------------------------------------------------------------------

here sample output for the "PCI" string:

PCI standard host CPU bridge                     PCI\VEN_1022&DEV_1400&SUBSYS_00000000&REV_00                     PCI bus 0, device 24, function 0         
PCI standard host CPU bridge                     PCI\VEN_1022&DEV_1401&SUBSYS_00000000&REV_00                     PCI bus 0, device 24, function 1         
PCI standard host CPU bridge                     PCI\VEN_1022&DEV_1402&SUBSYS_00000000&REV_00                     PCI bus 0, device 24, function 2         
PCI standard host CPU bridge                     PCI\VEN_1022&DEV_1403&SUBSYS_00000000&REV_00                     PCI bus 0, device 24, function 3         
PCI standard host CPU bridge                     PCI\VEN_1022&DEV_1404&SUBSYS_00000000&REV_00                     PCI bus 0, device 24, function 4         
PCI standard host CPU bridge                     PCI\VEN_1022&DEV_1405&SUBSYS_00000000&REV_00                     PCI bus 0, device 24, function 5         
PCI standard host CPU bridge                     PCI\VEN_1022&DEV_1410&SUBSYS_14101022&REV_00                     PCI bus 0, device 0, function 0          
PCI Express standard Root Port                   PCI\VEN_1022&DEV_1412&SUBSYS_12341022&REV_00                     PCI bus 0, device 2, function 0          
PCI Express standard Root Port                   PCI\VEN_1022&DEV_1414&SUBSYS_12341022&REV_00                     PCI bus 0, device 4, function 0          
PCI Express standard Root Port                   PCI\VEN_1022&DEV_1417&SUBSYS_12341022&REV_00                     PCI bus 0, device 7, function 0          
AMD IOMMU Device                                 PCI\VEN_1022&DEV_1419&SUBSYS_14191022&REV_00                     PCI bus 0, device 0, function 2          
AMD SATA Controller                              PCI\VEN_1022&DEV_7801&SUBSYS_B0021458&REV_40                     PCI bus 0, device 17, function 0         
Standard OpenHCD USB Host Controller             PCI\VEN_1022&DEV_7807&SUBSYS_50041458&REV_11                     PCI bus 0, device 18, function 0         
Standard OpenHCD USB Host Controller             PCI\VEN_1022&DEV_7807&SUBSYS_50041458&REV_11                     PCI bus 0, device 19, function 0         
Standard Enhanced PCI to USB Host Controller     PCI\VEN_1022&DEV_7808&SUBSYS_50041458&REV_11                     PCI bus 0, device 18, function 2         
Standard Enhanced PCI to USB Host Controller     PCI\VEN_1022&DEV_7808&SUBSYS_50041458&REV_11                     PCI bus 0, device 19, function 2         
Standard OpenHCD USB Host Controller             PCI\VEN_1022&DEV_7809&SUBSYS_50041458&REV_11                     PCI bus 0, device 20, function 5         
AMD SMBus                                        PCI\VEN_1022&DEV_780B&SUBSYS_780B1022&REV_14                     PCI bus 0, device 20, function 0         
High Definition Audio Controller                 PCI\VEN_1022&DEV_780D&SUBSYS_A0021458&REV_01                     PCI bus 0, device 20, function 2         
PCI standard ISA bridge                          PCI\VEN_1022&DEV_780E&SUBSYS_780E1022&REV_11                     PCI bus 0, device 20, function 3         
PCI standard PCI-to-PCI bridge                   PCI\VEN_1022&DEV_780F&SUBSYS_00000000&REV_40                     PCI bus 0, device 20, function 4         
AMD USB 3.0 Host Controller                      PCI\VEN_1022&DEV_7812&SUBSYS_50041458&REV_03                     PCI bus 0, device 16, function 0         
AMD USB 3.0 Host Controller                      PCI\VEN_1022&DEV_7812&SUBSYS_50041458&REV_03                     PCI bus 0, device 16, function 1         
High Definition Audio Controller                 PCI\VEN_10DE&DEV_0BEE&SUBSYS_35371458&REV_A1                     PCI bus 1, device 0, function 1          
NVIDIA GeForce GTX 550 Ti                        PCI\VEN_10DE&DEV_1244&SUBSYS_35371458&REV_A1                     PCI bus 1, device 0, function 0          
Realtek PCIe GBE Family Controller               PCI\VEN_10EC&DEV_8168&SUBSYS_E0001458&REV_06                     PCI bus 2, device 0, function 0          
MSI TV@Anywhere Plus                             PCI\VEN_1131&DEV_7133&SUBSYS_62311462&REV_D1                     PCI bus 4, device 6, function 0          
Etron USB 3.0 Extensible Host Controller         PCI\VEN_1B6F&DEV_7023&SUBSYS_50071458&REV_01                     PCI bus 3, device 0, function 0          

Just ignore the VCL stuff. The important stuff is USBinfo() function (yes I use it to obtain USB info). It will enumerate all the devices (like in Device Manager) matching string you init it with (the 3 similar lines 2 of them remed out). Just be clear AnsiString is string class (elements are accessed from [1] instead of [0]) and DWORD is unsigned 32 bit int. The Main->mm_log is just TMemo where I output the results. Do not forget to include setupapi.h

The interface can fetch any information you found in the device manager of Windows just use the SPDRP_ property you need (they are listed in the setupapi.h here is what mine contains:

#define SPDRP_DEVICEDESC                  (0x00000000)  // DeviceDesc (R/W)
#define SPDRP_HARDWAREID                  (0x00000001)  // HardwareID (R/W)
#define SPDRP_COMPATIBLEIDS               (0x00000002)  // CompatibleIDs (R/W)
#define SPDRP_UNUSED0                     (0x00000003)  // unused
#define SPDRP_SERVICE                     (0x00000004)  // Service (R/W)
#define SPDRP_UNUSED1                     (0x00000005)  // unused
#define SPDRP_UNUSED2                     (0x00000006)  // unused
#define SPDRP_CLASS                       (0x00000007)  // Class (R--tied to ClassGUID)
#define SPDRP_CLASSGUID                   (0x00000008)  // ClassGUID (R/W)
#define SPDRP_DRIVER                      (0x00000009)  // Driver (R/W)
#define SPDRP_CONFIGFLAGS                 (0x0000000A)  // ConfigFlags (R/W)
#define SPDRP_MFG                         (0x0000000B)  // Mfg (R/W)
#define SPDRP_FRIENDLYNAME                (0x0000000C)  // FriendlyName (R/W)
#define SPDRP_LOCATION_INFORMATION        (0x0000000D)  // LocationInformation (R/W)
#define SPDRP_PHYSICAL_DEVICE_OBJECT_NAME (0x0000000E)  // PhysicalDeviceObjectName (R)
#define SPDRP_CAPABILITIES                (0x0000000F)  // Capabilities (R)
#define SPDRP_UI_NUMBER                   (0x00000010)  // UiNumber (R)
#define SPDRP_UPPERFILTERS                (0x00000011)  // UpperFilters (R/W)
#define SPDRP_LOWERFILTERS                (0x00000012)  // LowerFilters (R/W)
#define SPDRP_BUSTYPEGUID                 (0x00000013)  // BusTypeGUID (R)
#define SPDRP_LEGACYBUSTYPE               (0x00000014)  // LegacyBusType (R)
#define SPDRP_BUSNUMBER                   (0x00000015)  // BusNumber (R)
#define SPDRP_ENUMERATOR_NAME             (0x00000016)  // Enumerator Name (R)
#define SPDRP_SECURITY                    (0x00000017)  // Security (R/W, binary form)
#define SPDRP_SECURITY_SDS                (0x00000018)  // Security (W, SDS form)
#define SPDRP_DEVTYPE                     (0x00000019)  // Device Type (R/W)
#define SPDRP_EXCLUSIVE                   (0x0000001A)  // Device is exclusive-access (R/W)
#define SPDRP_CHARACTERISTICS             (0x0000001B)  // Device Characteristics (R/W)
#define SPDRP_ADDRESS                     (0x0000001C)  // Device Address (R)
#define SPDRP_UI_NUMBER_DESC_FORMAT       (0X0000001D)  // UiNumberDescFormat (R/W)
#define SPDRP_DEVICE_POWER_DATA           (0x0000001E)  // Device Power Data (R)
#define SPDRP_REMOVAL_POLICY              (0x0000001F)  // Removal Policy (R)
#define SPDRP_REMOVAL_POLICY_HW_DEFAULT   (0x00000020)  // Hardware Removal Policy (R)
#define SPDRP_REMOVAL_POLICY_OVERRIDE     (0x00000021)  // Removal Policy Override (RW)
#define SPDRP_INSTALL_STATE               (0x00000022)  // Device Install State (R)
#define SPDRP_LOCATION_PATHS              (0x00000023)  // Device Location Paths (R)

#define SPDRP_MAXIMUM_PROPERTY            (0x00000024)  // Upper bound on ordinals

//
// Class registry property codes
// (Codes marked as read-only (R) may only be used for
// SetupDiGetClassRegistryProperty)
//
// These values should cover the same set of registry properties
// as defined by the CM_CRP codes in cfgmgr32.h.
// they should also have a 1:1 correspondence with Device registers, where applicable
// but no overlap otherwise
//
#define SPCRP_SECURITY                    (0x00000017)  // Security (R/W, binary form)
#define SPCRP_SECURITY_SDS                (0x00000018)  // Security (W, SDS form)
#define SPCRP_DEVTYPE                     (0x00000019)  // Device Type (R/W)
#define SPCRP_EXCLUSIVE                   (0x0000001A)  // Device is exclusive-access (R/W)
#define SPCRP_CHARACTERISTICS             (0x0000001B)  // Device Characteristics (R/W)
#define SPCRP_MAXIMUM_PROPERTY            (0x0000001C)  // Upper bound on ordinals

However As you collecting GPU info you might want to try also OpenGL approach:

You can collect list of supproted extentions and features and also obtain specific GPU info like number of pipelines, texture units, for some even free memory ...

Spektre
  • 49,595
  • 11
  • 110
  • 380