如何在c++中获取有关网络适配器的信息?

发布于 2024-09-24 17:33:59 字数 158 浏览 1 评论 0原文

如何获取系统中所有网络适配器的信息? 名称、制造商、位置(PCI、插槽2)、驱动程序版本。 实际上,我使用 WMI 检索了名称和制造商,但找不到位置和驱动程序版本。 我只需要 C++ 解决方案而不是 MFC/clr。 winapi函数? wmi(缺少一些东西)? 我还需要检索系统上的.NET 版本。

How to get information about all network adapters in system?
Name, Manufacturer, Location(PCI, slot2), Driver Version.
Actually i retrieved Name and Manufacturer with WMI but i can't find Location and Driver version.
I need only c++ solutions not MFC/clr.
winapi function? wmi (missing something)?
Also i need to retrieve .NET version on system.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心的位置 2024-10-01 17:33:59

参考您的第二个请求:“我需要在系统上检索 .NET 版本”

这可以通过 非托管托管 API。如果您使用的是 .NET 4.0,则可以使用新的 ICLRMetaHost 接口。 EnumerateInstalledRuntimes() 函数将给出你们当前都安装了 .NET 运行时。

您也可以使用 WMI 来完成此操作,但这需要更多的工作。安装 .NET 时,会创建一个 WMI Win32_Product 对象。使用 WMI Studio< /a> 您可以连接到 root\CIMV2 (Windows 7),导航到 CIM_Product\Win32_Product,并查看所有 MSI 安装的应用程序的所有 WMI 对象。您将能够在那里找到框架的所有已安装实例,并确定如何在代码中识别它们。

只需提及您可以从 WMI 获得与网络适配器驱动程序相关的内容。我假设您正在使用 Win32_NetworkAdapter 对象。该对象的 ServiceName 属性与表示用于该适配器的驱动程序的 Win32_SystemDriver 对象的 Name 属性相关联。 Win32_SystemDriver 对象没有版本信息,但它们确实具有实际文件二进制文件的路径。例如,我的无线网络适配器正在使用此驱动程序,C:\Windows\system32\DRIVERS\athr.sys。一旦获得完整的驱动程序路径,您就可以通过另一种机制获取文件的版本。

In reference to your second request: 'i need to retrieve .NET version on system'

This can be done via the Unmanaged Hosting API. If you are using .NET 4.0 then you can use the new ICLRMetaHost interface. The EnumerateInstalledRuntimes() function will give you all currently installed .NET runtimes.

You could also do this using WMI but it will require some more work. When installing .NET a WMI Win32_Product object is created. Using WMI Studio you can connect to root\CIMV2 (Windows 7), navigate to CIM_Product\Win32_Product, and view all WMI objects for all MSI installed applications. You will be able to find all installed instances of the framework there and determine how you want to identify them in code.

Just to mention what you can get from WMI with respect to the driver for your network adapter. I assume you are using the Win32_NetworkAdapter objects. The ServiceName property on that object is tied to the Name property of the Win32_SystemDriver object that represents the driver being used for that adapter. Win32_SystemDriver objects do have not version information but they do have paths to the actual file binary. For instance my wireless network adapter is using this driver, C:\Windows\system32\DRIVERS\athr.sys. Once you have the full driver path you may be able to get the version of the file via another mechanism.

樱娆 2024-10-01 17:33:59

我不知道 WMI 是否公开了这一点,但位置信息是通过 SetupAPI 函数从注册表获取的 SetupDiGetDeviceRegistryProperty 与 SPDRP_LOCATION_INFORMATION。

I don't know if WMI exposes this or not, but the location information is obtained from the registry via the SetupAPI function SetupDiGetDeviceRegistryProperty with SPDRP_LOCATION_INFORMATION.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文