c++ - nVidia driver version from WMI is not what I want -
i want driver version of nvidia video card. used wmi , data "driverversion" obejct of "win32_videocontroller" class. "9.18.13.1106"(file version) , wanted "311.06"(treiber version). can information? if impossible on wmi, want know other way that. thanks.
you can using nvml nvidia's tesla deployment kit. can retrieve internal driver version (the 1 you're accustomed seeing nvidia driver) code 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 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 shut down nvml")); } }; } int main() { std::cout << "nvidia driver version: " << nvml().get_ver(); }
note if you're writing purely own use on machine you're free edit path, can simplify quite bit. of code deals fact uses nvml.dll
, in directory that's not on path, code loads dynamically, , uses getprocaddress
find functions in need use. in case, we're using 3 functions, it's not difficult deal with, still @ drastically increases length of code.
if ignore nonsense, real code come out on general order:
nvmlinit(); nvmlsystemgetdriverversion(result, sizeof(result)); std::cout << result; nvmlshutdown();
anyway, build it, you'll need command line like:
cl -ic:\tdk\nvml\include nv_driver_version.cpp
...assuming you've installed tesla deployment kit @ c:\tdk
.
in case, yes, i've tested @ least degree. on desktop prints out:
nvidia driver version: 314.22
...which matches have installed.
Comments
Post a Comment