nVidia驱动程序版本从WMI不是我想要的 [英] nVidia driver version from WMI is not what I want

查看:2639
本文介绍了nVidia驱动程序版本从WMI不是我想要的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要获得驱动程序版本的nVidia视频卡。
所以我使用WMI并从Win32_VideoController类的DriverVersionobejct获取数据。
但是它像9.18.13.1106(文件版本),我想要的是像311.06(treiber版本)。
在哪里可以获得这些信息?
如果在WMI上不可能,我想知道其他方法来获得。
感谢。

I want to get driver version of nVidia video card. So I used WMI and get data from "DriverVersion" obejct of "Win32_VideoController" class. But it was like "9.18.13.1106"(file version) and what I wanted is something like "311.06"(treiber version). Where can I get that information? If it is impossible on WMI, I want to know other way to get that. Thanks.

推荐答案

您可以使用NVVi从nVidia的 Tesla Deployment Kit 。您可以使用以下代码检索内部驱动程序版本(您已经习惯使用nVidia驱动程序):

You can do this using NVML from nVidia's Tesla Deployment Kit. You can retrieve the internal driver version (the one you're accustomed to seeing for an nVidia driver) with code like this:

#include <iostream>
#include <string>
#include <stdlib.h>
#include <nvml.h>
#include <windows.h>

namespace { 
typedef nvmlReturn_t (*init)();
typedef nvmlReturn_t (*shutdown)();
typedef nvmlReturn_t (*get_version)(char *, unsigned);

class NVML {
    init nvmlInit;
    shutdown nvmlShutdown;
    get_version nvmlGetDriverVersion;

    std::string find_dll() {
        std::string loc(getenv("ProgramW6432"));
        loc += "\\Nvidia Corporation\\nvsmi\\nvml.dll";
        return loc;
    }

public:    
    NVML() {
        HMODULE lib = LoadLibrary(find_dll().c_str());
        nvmlInit = (init)GetProcAddress(lib, "nvmlInit");
        nvmlShutdown = (shutdown)GetProcAddress(lib, "nvmlShutdown");
        nvmlGetDriverVersion = (get_version)GetProcAddress(lib, "nvmlSystemGetDriverVersion");

        if (NVML_SUCCESS != nvmlInit())
            throw(std::runtime_error("Unable to initialize NVML"));
    }

    std::string get_ver() {
        char buffer[81];
        nvmlGetDriverVersion(buffer, sizeof(buffer));
        return std::string(buffer);
    }

    ~NVML() {
        if (NVML_SUCCESS != nvmlShutdown())
            throw(std::runtime_error("Unable to shut down NVML"));
    }
};
}

int main() {  
    std::cout << "nVidia Driver version: " << NVML().get_ver();
}

请注意,如果你只是为了自己在机器上使用在那里你可以自由编辑PATH,你可以简化这个有点。大多数代码处理这个事实,即它使用 NVML.DLL ,这是在一个通常不在路径上的目录,因此代码加载动态,并使用 GetProcAddress 找到我们需要使用的函数。在这种情况下,我们只使用了三个函数,所以这并不难处理,但它仍然会大大增加代码的长度。

Note that if you're writing this purely for your own use on a machine where you're free to edit the PATH, you can simplify this quite a bit. Most of the code deals with the fact that this uses NVML.DLL, which is in a directory that's not normally on the path, so the code loads that dynamically, and uses GetProcAddress to find the functions in it that we need to use. In this case, we're only using three functions, so it's not all that difficult to deal with, but it still at drastically increases the length of the code.

如果我们可以忽略所有这些废话,真正的代码只会出来的东西在这个一般的顺序:

If we could ignore all that nonsense, the real code would just come out to something on this general order:

nvmlInit();
nvmlSystemGetDriverVersion(result, sizeof(result));
std::cout << result;
nvmlShutdown();

无论如何,要构建它,你需要一个命令行:

Anyway, to build it, you'll need a command line something like:

 cl -Ic:\tdk\nvml\include nv_driver_version.cpp

...假设您已经在 c:\tdk 安装了Tesla部署工具包。

...assuming you've installed the Tesla Deployment Kit at c:\tdk.

在任何情况下,是的,我已经测试了这至少在一定程度上。在我的桌面上打印出来:

In any case, yes, I've tested this to at least some degree. On my desktop it prints out:

nVidia Driver version: 314.22

...与我安装的程序相符。

...which matches what I have installed.

这篇关于nVidia驱动程序版本从WMI不是我想要的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆