【问题标题】:Detailed PCI-E information, Windows详细的 PCI-E 信息,Windows
【发布时间】:2017-12-16 19:43:25
【问题描述】:

我有一个项目,我需要从带有图形卡的计算机收集信息,从 1 到 12,它有。然后将这些信息保存在云中以供以后使用。

我最需要的是:

它是什么 GPU 多少内存 它正在使用哪个 PCI 插槽,1、2、3 等(或任何名称)

Windows WMI 似乎有一些信息,我一直在查看不同的类,但似乎很难找到 PCI-E 插槽。有谁知道如何获取这些信息?

【问题讨论】:

  • 为什么投反对票?是的,OP 不包含他当前尝试的任何代码,但我觉得这仍然是相关的问题。在我看来,对没有任何 cmet 更改/修复或至少有什么问题的低代表用户投反对票是没有用的。

标签: graphics wmi pci


【解决方案1】:

您应该寻找 PCI 插槽 我在字符串中没有看到任何 PCI-E 定义(并不意味着没有)。如果我只尝试"PCI",结果会枚举 PCIPCI-E 设备。在 BDS2006 C++/VCL 中,我使用 this(我前段时间失败了)只是通过更改匹配字符串:

//---------------------------------------------------------------------------
//$$---- 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();
    }
//-------------------------------------------------------------------------

"PCI" 字符串的示例输出:

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          

忽略 VCL 的东西。重要的是USBinfo() 函数(是的,我用它来获取USB 信息)。它将枚举与您初始化它的字符串匹配的所有设备(如在设备管理器中)(其中 3 条类似的行 2 已被删除)。请明确AnsiString 是字符串类(从[1] 而不是[0] 访问元素)并且DWORD 是无符号的32 位整数。 Main-&gt;mm_log 就是我输出结果的TMemo。不要忘记包含setupapi.h

该界面可以获取您在 Windows 设备管理器中找到的任何信息,只需使用您需要的 SPDRP_ 属性(它们在 setupapi.h 中列出,这是我的内容:

#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

但是,当您收集 GPU 信息时,您可能还想尝试 OpenGL 方法:

您可以收集支持的扩展和功能列表,还可以获取特定的 GPU 信息,例如管道数量、纹理单元,甚至还有一些可用内存...

【讨论】:

    猜你喜欢
    • 2012-05-21
    • 2011-03-27
    • 2011-03-27
    • 2018-06-27
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    相关资源
    最近更新 更多